InMemorySingletonLeaseStore
AgentPrism.Core.dllA store that keeps singleton execution leases in process memory.
public sealed class InMemorySingletonLeaseStore : ISingletonLeaseStoreInheritance
Section titled “Inheritance”object ← InMemorySingletonLeaseStore
Implements
Section titled “Implements”Inherited Members
Section titled “Inherited Members”object.GetType(), object.ToString(), object.Equals(object?), object.Equals(object?, object?), object.ReferenceEquals(object?, object?), object.GetHashCode()
Remarks
Section titled “Remarks”In a single-process deployment, it always acquires the lease because
there is no competitor. A multi-process deployment needs a SQL provider,
SqlSingletonLeaseStore, for real coordination.
Limits: process lifetime and a single node.
Constructors
Section titled “Constructors”InMemorySingletonLeaseStore(TimeProvider?)
Section titled “ InMemorySingletonLeaseStore(TimeProvider?)”Initializes a new in-memory lease store.
public InMemorySingletonLeaseStore(TimeProvider? timeProvider = null)Parameters
Section titled “Parameters”timeProvider TimeProvider?
The time provider. Uses TimeProvider.System when omitted.
Methods
Section titled “Methods”ReleaseAsync(string, string, CancellationToken)
Section titled “ ReleaseAsync(string, string, CancellationToken)”Releases the lease. It does nothing when the caller is not the owner.
public ValueTask ReleaseAsync(string name, string ownerId, CancellationToken cancellationToken = default)Parameters
Section titled “Parameters”name string
The name of the lease.
ownerId string
The id of the instance that claims to hold the lease.
cancellationToken CancellationToken
The cancellation token.
Returns
Section titled “Returns”A task that completes when the work is done.
RenewAsync(string, string, TimeSpan, CancellationToken)
Section titled “ RenewAsync(string, string, TimeSpan, CancellationToken)”Extends the lease that is held. It returns false when the lease has moved to someone else — the caller MUST then drop the job.
public ValueTask<bool> RenewAsync(string name, string ownerId, TimeSpan duration, CancellationToken cancellationToken = default)Parameters
Section titled “Parameters”name string
The name of the lease.
ownerId string
The id of the instance that claims to hold the lease.
duration TimeSpan
The new lease duration.
cancellationToken CancellationToken
The cancellation token.
Returns
Section titled “Returns”true when the renewal succeeded.
TryAcquireAsync(string, string, TimeSpan, CancellationToken)
Section titled “ TryAcquireAsync(string, string, TimeSpan, CancellationToken)”Tries to take the lease. It returns false when someone else holds the lease and it has not expired.
public ValueTask<bool> TryAcquireAsync(string name, string ownerId, TimeSpan duration, CancellationToken cancellationToken = default)Parameters
Section titled “Parameters”name string
The name of the lease (the id of the protected job).
ownerId string
The id of this instance.
duration TimeSpan
How long the lease stays valid.
cancellationToken CancellationToken
The cancellation token.
Returns
Section titled “Returns”true when the lease was taken.