Class WorkManagerRecoveryHostedService
- Namespace
- Virtufin.WorkManager.Services
- Assembly
- Virtufin.WorkManager.dll
Hosted service that automatically recovers workers on application startup, gated by Enabled and coordinated across multiple WorkManager instances via RecoveryLeaderElector.
When multiple instances start concurrently, only the leader performs recovery — the others wait for the leader lease to expire (or be released) before they would attempt to take over. This avoids the N×W engine-load waste described in WM #4.
Kestrel readiness is gated via RecoveryHealthCheck:
Degradedwhile recovery is in progress.Unhealthyif recovery failed.Healthyonce recovery completes (whether this instance performed it or another leader did).
public sealed class WorkManagerRecoveryHostedService : BackgroundService, IHostedService, IDisposable
- Inheritance
-
WorkManagerRecoveryHostedService
- Implements
- Inherited Members
Constructors
WorkManagerRecoveryHostedService(IWorkerRecoveryExecutor, IRecoveryLeaderElector, ILogger<WorkManagerRecoveryHostedService>, RecoveryState, WorkerRecoveryOptions)
public WorkManagerRecoveryHostedService(IWorkerRecoveryExecutor executor, IRecoveryLeaderElector leaderElector, ILogger<WorkManagerRecoveryHostedService> logger, RecoveryState recoveryState, WorkerRecoveryOptions options)
Parameters
executorIWorkerRecoveryExecutorleaderElectorIRecoveryLeaderElectorloggerILogger<WorkManagerRecoveryHostedService>recoveryStateRecoveryStateoptionsWorkerRecoveryOptions
Methods
ExecuteAsync(CancellationToken)
This method is called when the IHostedService starts. The implementation should return a task that represents the lifetime of the long running operation(s) being performed.
protected override Task ExecuteAsync(CancellationToken stoppingToken)
Parameters
stoppingTokenCancellationTokenTriggered when StopAsync(CancellationToken) is called.
Returns
Remarks
See Worker Services in .NET for implementation guidelines.