IDeliveryLease Interface
A claim on one named piece of delivery work, held for a bounded time, so that among however many transmitter instances are running exactly one performs it.
public interface IDeliveryLeaseDerived
↳ ProcessLocalDeliveryLease
Remarks
Push delivery reads a stream's queue and empties it as receipts come back, so two instances sweeping one stream both read the same pending SETs and both POST them. RFC 8935 Section 2 permits a receiver to be sent the same SET again - "The SET Recipient MUST respond as it would if the SET had not been previously received" - but binds the transmitter the other way: it "should not retransmit a SET unless the SET Transmitter suspects that previous transmissions may have failed due to potentially recoverable errors", and "in all other cases, the SET Transmitter SHOULD NOT retransmit a SET". Instances duplicating each other's work suspect nothing, so this is that SHOULD NOT rather than a matter of wasted traffic.
The claim EXPIRES, and that is what separates it from a lock. Expiry is what lets an instance that died mid-pass release its claim without running any code - nothing else would - and it is therefore also the point past which the holder has no claim at all. So a holder must stop the work at its deadline rather than treat the lease as advice: whoever comes next is entitled to start, and two workers overlapping is the very thing being prevented.
Methods
IDeliveryLease.TryAcquireAsync(string, TimeSpan, CancellationToken) Method
Claims name for at most duration.
System.Threading.Tasks.Task<System.IAsyncDisposable?> TryAcquireAsync(string name, System.TimeSpan duration, System.Threading.CancellationToken cancellationToken=default(System.Threading.CancellationToken));Parameters
name System.String
What is being claimed. Callers scope it themselves, so two kinds of work over one stream do not collide.
duration System.TimeSpan
How long the claim holds without being released. It bounds two opposite costs: too short cuts a legitimate pass off and the work is redone next time, too long parks the work for the remainder after the holder dies. Both are safe, so err on whichever the deployment minds less.
cancellationToken System.Threading.CancellationToken
Cancels the I/O a shared implementation performs.
Returns
System.Threading.Tasks.Task<System.IAsyncDisposable>
A handle that releases the claim when disposed, or null when someone else holds it - which
is an ordinary outcome and not a failure. Releasing is conditional on still holding it, so
a handle disposed after its deadline cannot revoke the claim of whoever took over.