Table of Contents

Class RecoveryLeaderElector

Namespace
Virtufin.WorkManager.Services
Assembly
Virtufin.WorkManager.dll

Lease-based leader election backed by the Dapr state store. Multiple WorkManager instances can race to acquire a lease for the workmanager/recovery/leader key; only the holder performs worker recovery. The lease has a TTL so a crashed instance's lease expires automatically and another instance can take over.

public sealed class RecoveryLeaderElector : IRecoveryLeaderElector
Inheritance
RecoveryLeaderElector
Implements
Inherited Members

Constructors

RecoveryLeaderElector(DaprClient, string, string, ILogger<RecoveryLeaderElector>, WorkerRecoveryOptions)

public RecoveryLeaderElector(DaprClient daprClient, string stateStoreName, string instanceId, ILogger<RecoveryLeaderElector> logger, WorkerRecoveryOptions options)

Parameters

daprClient DaprClient
stateStoreName string
instanceId string
logger ILogger<RecoveryLeaderElector>
options WorkerRecoveryOptions

Fields

LeaseKey

Default state-store key for the recovery leader lease.

public const string LeaseKey = "workmanager/recovery/leader"

Field Value

string

Methods

ReleaseLeaseAsync()

Releases the lease iff this instance holds it. Safe to call on shutdown. Failures are logged but not propagated.

public Task ReleaseLeaseAsync()

Returns

Task

TryAcquireLeaseAsync(CancellationToken)

Tries to acquire the recovery leader lease. Returns true iff this instance is the recovery leader; false if another instance holds it or the acquire timed out. The lease auto-expires after the configured TTL.

public Task<bool> TryAcquireLeaseAsync(CancellationToken cancellationToken)

Parameters

cancellationToken CancellationToken

Returns

Task<bool>