package inbound import ( "context" "errors" "lincodex/backend/internal/port/outbound" ) // ErrJobRejected marks a handler failure that a retry cannot fix, for // example a payload that breaks the contract of its kind. The worker makes // the job dead at once instead of retrying it. var ErrJobRejected = errors.New("scheduled job rejected by handler") // JobHandler runs scheduled jobs of one kind when they fall due. The worker // calls Handle inside the transaction that marks the job done, so a // database-only effect and the completion commit together and a job is // applied once even when workers race or restart. An effect outside the // database, such as a call to another service, can repeat after a crash // and must be idempotent on its own. type JobHandler interface { // JobKind is the stable kind name the handler runs, a lowercase dotted // name of at most 64 bytes. Renaming it strands the scheduled jobs of // the old name. JobKind() string // Handle runs job with unit and the context it receives only. The // context ends when the lease does. A handler decides by job.DueAt, the // deadline the job stands for, which retries keep, rather than by the // time it happens to run. An error rolls back the effect; one matching ErrJobRejected is // final, any other is retried with backoff a bounded number of times. // Errors must not quote the payload or personal data; the worker logs // a sanitized reason and stores only a bounded class. Handle(ctx context.Context, unit outbound.UnitOfWork, job outbound.ClaimedJob) error }