feat: Add health check monitoring for ProfileWorker

ProfileWorker changes:
- Implement IHealthCheck interface
- Replace _workCount with DateTime-based tracking
- Track _lastSuccessfulRun, _consecutiveFailures, _lastException
- Graceful shutdown handling (OperationCanceledException)
- Health states: Healthy, Degraded (1-2 failures), Unhealthy (3x interval)

DependencyInjection changes:
- Register ProfileWorker as singleton (for health check access)
- Use factory pattern for IHostedService registration

Program.cs changes:
- Add health check service with ProfileWorker
- Map /health endpoint (full JSON response with all checks)
- Map /health/ready endpoint (filtered by 'ready' tag)
- Custom JSON response writer with detailed metrics
This commit is contained in:
2026-07-13 12:19:11 +02:00
parent b48e3d1823
commit 8a05d86285
3 changed files with 128 additions and 10 deletions

View File

@@ -13,9 +13,13 @@ public static class DependencyInjection
// Validate options at startup
services.AddSingleton<IValidateOptions<ProfileWorkerOptions>, ProfileWorkerOptionsValidator>();
services.AddHostedService<ProfileWorker>();
// Register ProfileWorker as both HostedService and singleton (for health check access)
services.AddSingleton<ProfileWorker>();
services.AddHostedService(sp => sp.GetRequiredService<ProfileWorker>());
services.AddSingleton<ProfileCache>();
services.AddScoped<ProfileWork>();
return services;
}
}