Table of Contents

Class JobExecutor

Namespace
MailFathom.Application.Jobs.Execution
Assembly
MailFathom.Application.dll

Runs one leased job through its handler, holds the lease while it works, and records how it ended.

public sealed class JobExecutor
Inheritance
JobExecutor
Inherited Members

Remarks

Three things can stop a handler and they are not the same event. Host shutdown gives the lease back, so the job is claimable immediately and the deployment costs it nothing; the execution timeout records a failure, because the job exceeded what it was allowed; and a lost lease writes nothing at all, because the row already belongs to the attempt that replaced this one. Collapsing the three would make a rolling restart read as a burst of failures and would let a late writer overwrite a newer attempt's outcome.

The lease is renewed while the handler works, so a job that legitimately takes longer than one lease is not reclaimed underneath it. A renewal the store refuses is the signal that it already was: the attempt is cancelled at once, so the handler stops rather than going on to produce a second execution's effects.

Every write recording an outcome is made outside the caller's cancellation, deliberately. The one moment a result most needs to be durable is the shutdown that stopped the work, and a write cancelled by the same token as the handler would leave the job held until its lease ran out on its own.

A failure is classified before the attempt budget is consulted, which is what keeps a permanent failure from spending the budget several times over to reach the answer it had on its first attempt. Only a transient failure is scheduled again, on a jittered delay; a permanent one, and a transient one that has run out of attempts, becomes a dead letter that keeps the classification and the reason it ended on.

Constructors

JobExecutor(IJobStore, JobHandlerRegistry, IJobFailureClassifier, JobExecutionSettings, TimeProvider)

Initializes the executor from the queue it writes to and the bounds it runs under.

Methods

ExecuteAsync(LeasedJob, CancellationToken)

Runs one job this process holds a lease on, and records the outcome against it.