Table of Contents

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:

  • Degraded while recovery is in progress.
  • Unhealthy if recovery failed.
  • Healthy once 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

executor IWorkerRecoveryExecutor
leaderElector IRecoveryLeaderElector
logger ILogger<WorkManagerRecoveryHostedService>
recoveryState RecoveryState
options WorkerRecoveryOptions

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

stoppingToken CancellationToken

Triggered when StopAsync(CancellationToken) is called.

Returns

Task

A Task that represents the long running operations.

Remarks

See Worker Services in .NET for implementation guidelines.