// Package tasks - per-table background task queues with retry. package tasks import ( "context" "time" ) type Task struct { TaskID string // Origin is the request ID of the request that enqueued the task, // linking the task's execution trace back to its cause. Origin string Payload []byte Status Status Attempts int RunAfter time.Time LeaseUntil *time.Time CreatedAt time.Time } //atlas:enum Status Pending Processing Completed Failed // Result is the standard envelope a task endpoint includes in its response // body as the "Task" field, telling the worker how the run ended // independently of HTTP status codes. Responses without an envelope fall // back to status-code mapping: 2xx completed, 429/5xx retry, other 4xx // failed. type Result struct { Outcome Outcome // Error says why, for failed and retry outcomes. Error string } //atlas:enum Outcome Completed Failed Retry type Producer[T any] interface { Create(ctx context.Context, payload T) error } // Consumer claims and manages tasks. Used by the worker. type Consumer interface { Claim(ctx context.Context, leaseDuration time.Duration, limit int) ([]Task, error) Complete(ctx context.Context, taskID string) error Retry(ctx context.Context, taskID string, runAfter time.Time) error Fail(ctx context.Context, taskID string) error }