// Package tasks - per-table background task queues with retry. package tasks import ( "context" "time" ) type Task struct { ID int64 Payload []byte Status Status Attempts int RunAfter time.Time LeaseUntil *time.Time CreatedAt time.Time } type Status string const ( StatusPending Status = "pending" StatusProcessing Status = "processing" StatusCompleted Status = "completed" StatusFailed Status = "failed" ) type Producer interface { // TODO payload should maybe be "any" and look for marshaljson or marshalbinary? Push(ctx context.Context, name string, payload []byte) 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, id int64) error Retry(ctx context.Context, id int64, runAfter time.Time) error Fail(ctx context.Context, id int64) error }