Table of Contents

Class JobConcurrencyGate

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

Hands out the right to run one job, under a ceiling for the process and a ceiling for the job's own type.

public sealed class JobConcurrencyGate : IDisposable
Inheritance
JobConcurrencyGate
Implements
Inherited Members

Remarks

The bound belongs to the process rather than to a pass, which is why this is held once and shared: a pass is a unit of claiming, and how much of the instance background work may take is a statement about the instance. A deployment running several replicas therefore bounds in-flight work at this ceiling times the replica count, which is legible but is not a deployment-wide limit; providing one would need a counted claim or an advisory lock, and nothing has asked for it.

The type's slot is taken before the process slot, and that ordering is the whole isolation guarantee. A job waiting for its own type to free up holds nothing of the process ceiling, so a flood of one kind of work cannot occupy the capacity another kind would have run in. Taking the process slot first would let a queue of one type sit on every slot while blocked, which is the starvation the per-type ceiling exists to prevent.

Every declared type gets its own slots at construction rather than on first use. The set is closed, so there is nothing to grow at run time and no lock to take on the way to a permit.

Constructors

JobConcurrencyGate(JobCapacitySettings)

Initializes the gate from the capacity the deployment configured.

Methods

AcquireAsync(JobType, CancellationToken)

Waits until this process may run one more job of the given type.

Dispose()

Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.