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:
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user