{"record":{"id":"f24b6b0900ff374c","repo":"Billionmail/BillionMail","slug":"failed-to-update-task-pause-status-w","errorCode":null,"errorMessage":"failed to update task pause status: %w","messagePattern":"failed to update task pause status: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"core/internal/service/batch_mail/batch_mail.go","lineNumber":556,"sourceCode":"func UpdateTaskPauseStatus(ctx context.Context, taskId int, isPaused bool) error {\n\tpauseValue := 0\n\tprocessValue := 1\n\n\tif isPaused {\n\t\tpauseValue = 1\n\t\tprocessValue = 3\n\t}\n\n\t_, err := g.DB().Model(\"email_tasks\").\n\t\tWhere(\"id\", taskId).\n\t\tData(g.Map{\n\t\t\t\"pause\":        pauseValue,\n\t\t\t\"task_process\": processValue,\n\t\t}).\n\t\tUpdate()\n\n\tif err != nil {\n\t\treturn fmt.Errorf(\"failed to update task pause status: %w\", err)\n\t}\n\n\tg.Log().Info(ctx, \"Updated task %d pause status: isPaused=%v, task_process=%d\", taskId, isPaused, processValue)\n\treturn nil\n}\n\n// UpdateTaskProcessStatus update task process status\nfunc UpdateTaskProcessStatus(ctx context.Context, taskId int, status int) error {\n\t_, err := g.DB().Model(\"email_tasks\").\n\t\tWhere(\"id\", taskId).\n\t\tData(g.Map{\"task_process\": status}).\n\t\tUpdate()\n\n\tif err != nil {\n\t\treturn fmt.Errorf(\"failed to update task process status: %w\", err)\n\t}\n\n\treturn nil","sourceCodeStart":538,"sourceCodeEnd":574,"githubUrl":"https://github.com/Billionmail/BillionMail/blob/fc36c76c050c3775c5e899faf7403cf0262d2744/core/internal/service/batch_mail/batch_mail.go#L538-L574","documentation":"UpdateTaskPauseStatus updates is_paused and task_process on an email_tasks row. A failed UPDATE is wrapped as \"failed to update task pause status: %w\". This is a write failure at the DB level; the function logs success afterward only if the update succeeded.","triggerScenarios":"PauseTask or ResumeTask calls this while the UPDATE fails: DB connection lost, table locked by long transactions, permission denied on UPDATE, or a trigger/constraint on email_tasks rejecting the values.","commonSituations":"Toggling pause/resume from the UI during a Postgres restart; concurrent bulk updates holding row locks; read-only replica routed for writes; schema change without the new columns present.","solutions":["Inspect the wrapped driver error to identify the DB cause","Check for lock contention on the email_tasks row and long-running transactions","Verify UPDATE permission on email_tasks and that writes go to the primary","Retry the pause/resume operation once the DB is healthy"],"exampleFix":null,"handlingStrategy":"retry","validationCode":"if taskId <= 0 {\n    return errors.New(\"invalid taskId\")\n}","typeGuard":null,"tryCatchPattern":"if err := UpdateTaskPauseStatus(ctx, taskId, isPaused, process); err != nil {\n    if isTransientDBError(err) {\n        time.Sleep(time.Second)\n        return UpdateTaskPauseStatus(ctx, taskId, isPaused, process)\n    }\n    return err\n}","preventionTips":["Route writes to the primary, never a read replica","Monitor long transactions that lock email_tasks rows","Verify UPDATE grants for the app DB user after migrations","Make pause/resume idempotent so retries are safe"],"tags":["database","update","postgresql"],"backgroundTag":"database-update-failed","analyzedSha":"fc36c76c050c3775c5e899faf7403cf0262d2744","analyzedAt":"2026-09-05T21:28:54.019Z","contentChangedAt":"2026-09-05T21:28:54.019Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}