Interface IWorkLeaseStore
- Namespace
- MailFathom.Application.Coordination
- Assembly
- MailFathom.Application.dll
Hands exclusive hold of a named unit of work to one holder at a time, for as long as it keeps renewing.
public interface IWorkLeaseStore
Remarks
One mechanism for every kind of work that must not run twice — a mailbox supervisor, a deployment-wide sweep, an operator's re-derivation, the stored-content move — so that none of them grows an idea of its own about what holding work means. Which scope one unit of that work is, is the key its own progress row already carries.
The exclusion is the database's rather than this contract's. A claim is one statement that inserts the scope or takes over an expired lease, so two replicas asking for one scope at the same instant leave one holder because PostgreSQL refused the other, not because either checked first; and renewal and release are each a single conditional update that writes nothing once the lease has moved on.
No method here takes a persistence session, and that is the contract rather than an omission. A hold outlives the transaction that took it, because the work it guards reaches a mail server or a model provider and no transaction may stay open across one — so there is nothing for a caller to enlist a claim in, and a hold cannot be lost by a rollback somewhere above it.
What a holder is promised is at most one writer, and never at most one runner, which WorkLease states in full. A holder that fails to renew stops its own work rather than waiting for the expiry, and a scope's exclusion reaches MailFathom's own state rather than a connection a mail server has already accepted.
Methods
- ClaimAsync(WorkScope, WorkLeaseHolder, TimeSpan, CancellationToken)
Takes exclusive hold of a scope nothing holds, or whose holder's lease has run out.
- ReadEveryHeldAsync(int, CancellationToken)
Reads every scope the deployment is holding right now, whatever it names.
- ReadHeldAsync(IReadOnlyCollection<WorkScope>, CancellationToken)
Reads which of a set of scopes the deployment is holding right now, and under which replica.
- ReleaseAsync(WorkScope, WorkLeaseHolder, CancellationToken)
Gives a held scope back at once, so another replica can take it without waiting out the expiry.
- RenewAsync(WorkScope, WorkLeaseHolder, TimeSpan, CancellationToken)
Pushes a held lease further out, so a long-running hold is not taken from underneath it.