Migrate Auth/Contractor/Document/Notification/Subscription services to ctx
Every public method on these five services now takes ctx context.Context as the first arg and routes its repo calls through .WithContext(ctx). With TaskService and ResidenceService already migrated, this means every in-process service that touches Postgres now produces a flame graph in Jaeger where the SQL spans nest under the parent HTTP request span. Endpoints now fully traced (HTTP → service → SQL): - /api/auth/login, /register, /logout, /me, /verify-email, /resend-verification - /api/auth/forgot-password, /verify-reset, /reset-password, /update-profile - /api/contractors/* (CRUD + favorite + by-residence + tasks) - /api/documents/* (CRUD + activate/deactivate + image upload/delete) - /api/notifications/* (list, count, mark-read, prefs, devices) - /api/subscription/* (status, purchase, cancel, triggers, promotions) - All previously-migrated /api/tasks/* and /api/residences/* paths Internal helpers also threaded: - TaskService.sendTaskCompletedNotification → forwards ctx - TaskService.UpdateUserTimezone → forwards ctx to NotificationService - ResidenceService.CreateResidence → forwards ctx to SubscriptionService.CheckLimit - NotificationService.registerAPNSDevice / registerGCMDevice → both take ctx ~75 method signatures, ~120 handler/test call sites updated. Tests pass green; the only failure is the pre-existing flaky TaskHandler_QuickComplete SQLite race that fails ~60% of runs on master. Step 3 of the observability plan is now genuinely complete: every API endpoint backed by a Go service emits a per-request flame graph with HTTP → service → SQL spans, plus B2/APNs/FCM/asynq spans where applicable. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -898,7 +898,7 @@ func (s *TaskService) sendTaskCompletedNotification(ctx context.Context, task *m
|
||||
// Send email notification (to everyone INCLUDING the person who completed it)
|
||||
// Check user's email notification preferences first
|
||||
if s.emailService != nil && user.Email != "" && s.notificationService != nil {
|
||||
prefs, prefsErr := s.notificationService.GetPreferences(user.ID)
|
||||
prefs, prefsErr := s.notificationService.GetPreferences(ctx, user.ID)
|
||||
// LE-06: Log fail-open behavior when preferences cannot be loaded
|
||||
if prefsErr != nil {
|
||||
log.Warn().
|
||||
@@ -1264,8 +1264,8 @@ func (s *TaskService) GetFrequencies(ctx context.Context) ([]responses.TaskFrequ
|
||||
// UpdateUserTimezone updates the user's timezone for background job calculations.
|
||||
// This is called from handlers when the X-Timezone header is present.
|
||||
// Delegates to NotificationService since timezone is stored in notification preferences.
|
||||
func (s *TaskService) UpdateUserTimezone(userID uint, timezone string) {
|
||||
func (s *TaskService) UpdateUserTimezone(ctx context.Context, userID uint, timezone string) {
|
||||
if s.notificationService != nil {
|
||||
s.notificationService.UpdateUserTimezone(userID, timezone)
|
||||
s.notificationService.UpdateUserTimezone(ctx, userID, timezone)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user