Add XML documentation for improved code clarity
Added detailed XML documentation across multiple files to enhance code maintainability and readability. Key updates include: - Documented `AllowAllDashboardAuthorizationFilter` to clarify its development-only usage. - Added comments to `DtoExtensions` for Hangfire job ID generation and DTO-to-command conversion methods. - Enhanced `HealthCheckHtmlGenerator` with detailed descriptions of HTML generation methods and utility functions. - Documented `DependencyInjection` and `ProfileWorkerOptionsValidator` to explain service registration and configuration validation. - Updated `ProfileCache` with comments on thread-safe operations. - Added documentation to `ProfileWork` for profile synchronization logic and execution flow. - Enhanced `ProfileWorker` with health check logic and background service execution details. - Documented `ProfileWorkerOptions` configuration properties. These changes aim to improve developer understanding and ensure best practices are followed in production environments.
This commit is contained in:
@@ -3,6 +3,28 @@ using Microsoft.Extensions.Options;
|
||||
|
||||
namespace ECMJobRunner.WebCron.ProfileWorker;
|
||||
|
||||
/// <summary>
|
||||
/// Background service that continuously synchronizes active profiles with Hangfire recurring jobs.
|
||||
/// Implements health check monitoring to track service status and failure conditions.
|
||||
/// </summary>
|
||||
/// <param name="Logger">Logger for diagnostic output.</param>
|
||||
/// <param name="ScopeFactory">Factory for creating service scopes (required for scoped service resolution).</param>
|
||||
/// <param name="Options">Configuration options for interval timing.</param>
|
||||
/// <remarks>
|
||||
/// This service runs on a configurable interval (default 1 second) and performs the following:
|
||||
/// <list type="bullet">
|
||||
/// <item><description>Fetches active profiles from the database</description></item>
|
||||
/// <item><description>Synchronizes profiles with Hangfire recurring jobs</description></item>
|
||||
/// <item><description>Tracks health status based on success/failure patterns</description></item>
|
||||
/// <item><description>Gracefully handles cancellation during application shutdown</description></item>
|
||||
/// </list>
|
||||
/// Health states:
|
||||
/// <list type="bullet">
|
||||
/// <item><description><b>Healthy</b>: Last successful run within 3x interval</description></item>
|
||||
/// <item><description><b>Degraded</b>: 1-2 consecutive failures but within time limit</description></item>
|
||||
/// <item><description><b>Unhealthy</b>: No success for 3x interval or 3+ consecutive failures</description></item>
|
||||
/// </list>
|
||||
/// </remarks>
|
||||
public class ProfileWorker(
|
||||
ILogger<ProfileWorker> Logger,
|
||||
IServiceScopeFactory ScopeFactory,
|
||||
@@ -15,6 +37,19 @@ public class ProfileWorker(
|
||||
private int _consecutiveFailures = 0;
|
||||
private Exception? _lastException = null;
|
||||
|
||||
/// <summary>
|
||||
/// Background service execution loop that synchronizes profiles on a configurable interval.
|
||||
/// </summary>
|
||||
/// <param name="stoppingToken">Cancellation token for graceful shutdown.</param>
|
||||
/// <returns>A task representing the background execution.</returns>
|
||||
/// <remarks>
|
||||
/// The loop continues until:
|
||||
/// <list type="bullet">
|
||||
/// <item><description>Application shutdown is requested (via stoppingToken)</description></item>
|
||||
/// <item><description>An unhandled exception causes service failure</description></item>
|
||||
/// </list>
|
||||
/// Uses scoped services for each iteration to ensure proper lifetime management.
|
||||
/// </remarks>
|
||||
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
|
||||
{
|
||||
Logger.LogInformation("ProfileWorker started");
|
||||
@@ -61,6 +96,28 @@ public class ProfileWorker(
|
||||
Logger.LogInformation("ProfileWorker stopped");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Performs a health check by evaluating recent success/failure patterns.
|
||||
/// </summary>
|
||||
/// <param name="context">Health check context (unused).</param>
|
||||
/// <param name="cancellationToken">Cancellation token.</param>
|
||||
/// <returns>
|
||||
/// A <see cref="HealthCheckResult"/> indicating the current health status:
|
||||
/// <list type="bullet">
|
||||
/// <item><description><see cref="HealthStatus.Healthy"/> - Service running normally</description></item>
|
||||
/// <item><description><see cref="HealthStatus.Degraded"/> - Recent failures but still operational</description></item>
|
||||
/// <item><description><see cref="HealthStatus.Unhealthy"/> - No successful run for extended period</description></item>
|
||||
/// </list>
|
||||
/// </returns>
|
||||
/// <remarks>
|
||||
/// Health determination logic:
|
||||
/// <list type="number">
|
||||
/// <item><description><b>Unhealthy</b>: Time since last success exceeds 3x the configured interval</description></item>
|
||||
/// <item><description><b>Degraded</b>: 1+ consecutive failures within time threshold</description></item>
|
||||
/// <item><description><b>Healthy</b>: Recent successful run with no failures</description></item>
|
||||
/// </list>
|
||||
/// Includes diagnostic data in the result for monitoring and alerting.
|
||||
/// </remarks>
|
||||
public Task<HealthCheckResult> CheckHealthAsync(
|
||||
HealthCheckContext context,
|
||||
CancellationToken cancellationToken = default)
|
||||
|
||||
Reference in New Issue
Block a user