Table of Contents

Method ClaimAsync

Namespace
MailFathom.Application.Coordination
Assembly
MailFathom.Application.dll

ClaimAsync(WorkScope, WorkLeaseHolder, TimeSpan, CancellationToken)

Takes exclusive hold of a scope nothing holds, or whose holder's lease has run out.

Task<WorkLease?> ClaimAsync(WorkScope scope, WorkLeaseHolder holder, TimeSpan leaseDuration, CancellationToken cancellationToken)

Parameters

scope WorkScope

The unit of work to hold.

holder WorkLeaseHolder

The hold the lease would be stamped with.

leaseDuration TimeSpan

How long the scope is held from now, unless it is renewed.

cancellationToken CancellationToken

Cancels the claim.

Returns

Task<WorkLease>

The lease this call took, or null when the scope is held by an unexpired lease.

Remarks

An absent answer is not a failure and not something to report: the work is somebody else's for now, so a caller waits and asks again on the interval it would have run on. What holds what is a question the lease table answers about the deployment rather than one the replica that happened to ask answers about itself.

A holder that already holds the scope is refused as well, because a live lease is a live lease whoever asks. A holder extends what it has through RenewAsync(WorkScope, WorkLeaseHolder, TimeSpan, CancellationToken), which is the one operation that says so.

Exceptions

ArgumentNullException

Thrown when scope or holder is null.

ArgumentOutOfRangeException

Thrown when leaseDuration is not positive.