Interface IJobStore
- Namespace
- MailFathom.Application.Jobs
- Assembly
- MailFathom.Application.dll
Keeps durable background work, and hands each job to one worker at a time.
public interface IJobStore
Remarks
Two of the guarantees here are the schema's rather than this contract's. Enqueuing is idempotent because the job
type and the key are unique together in the database, so two callers asking for the same execution at the same
moment both reach it and one of them loses there; a check followed by a write would leave the window between the two
statements open, which is the window everything above depends on being closed. And a claim is exclusive because one
statement selects and stamps the row under FOR UPDATE SKIP LOCKED, so two workers claiming at once take
different jobs rather than waiting on each other.
No method here takes a persistence session, and that is the contract rather than an omission. A job is enqueued against state that is already committed — never inside the synchronization transaction that stored the message — so there is no session for a caller to join it to and no way to enqueue work whose subject may still roll back.
What this delivers is at-least-once execution and nothing stronger. Uniqueness stops the same work being enqueued twice; only a handler can stop a re-run after a crash from having a second effect, so a handler is registered on the promise that running it twice with one payload is the same as running it once.
Methods
- ClaimAsync(JobClaimRequest, CancellationToken)
Takes up to a batch of due jobs this process can run, and leases each of them to one attempt.
- CompleteAsync(JobId, JobLeaseOwner, CancellationToken)
Ends a held job as done, leaving a terminal row that keeps its key.
- DeadLetterAsync(JobId, JobLeaseOwner, JobFailureRecord, CancellationToken)
Ends a held job as work nothing will attempt again, leaving a terminal row that keeps its key and its last failure.
- EnqueueAsync(JobEnqueueRequest, CancellationToken)
Writes the execution down, reports the job that already carries this type and key, or refuses a queue that is full.
- FindStateAsync(JobId, CancellationToken)
Reads where one job stands, which is what a caller holding an identifier asks before acting on it.
- ReleaseAsync(JobId, JobLeaseOwner, CancellationToken)
Gives a held job back unfinished, so it is claimable again at once.
- RenewLeaseAsync(JobId, JobLeaseOwner, TimeSpan, CancellationToken)
Pushes a held job's lease further out, so a long execution is not reclaimed underneath it.
- ScheduleRetryAsync(JobId, JobLeaseOwner, JobFailureRecord, DateTimeOffset, CancellationToken)
Gives a held job back after a transient failure, claimable again once the instant named has passed.