Class HealthCheckService
- Namespace
- WorkflowForge.Extensions.Observability.HealthChecks
- Assembly
- WorkflowForge.Extensions.Observability.HealthChecks.dll
Service that manages and executes health checks for the WorkflowForge system.
public sealed class HealthCheckService : IDisposable
- Inheritance
-
HealthCheckService
- Implements
- Inherited Members
Constructors
HealthCheckService(IWorkflowForgeLogger, ISystemTimeProvider?, TimeSpan?, bool)
Initializes a new instance of the HealthCheckService class.
public HealthCheckService(IWorkflowForgeLogger logger, ISystemTimeProvider? timeProvider = null, TimeSpan? checkInterval = null, bool registerBuiltInHealthChecks = true)
Parameters
loggerIWorkflowForgeLoggerThe logger to use for health check operations.
timeProviderISystemTimeProviderThe time provider to use for timestamps.
checkIntervalTimeSpan?The interval for periodic health checks. Set to null to disable periodic checks.
registerBuiltInHealthChecksboolWhether to automatically register built-in health checks.
Properties
LastResults
Gets the results of the last health check execution.
public IReadOnlyDictionary<string, HealthCheckResult> LastResults { get; }
Property Value
OverallStatus
Gets the overall health status based on the last check results.
public HealthStatus OverallStatus { get; }
Property Value
Methods
CheckHealthAsync(string, CancellationToken)
Executes a specific health check by name.
public Task<HealthCheckResult?> CheckHealthAsync(string name, CancellationToken cancellationToken = default)
Parameters
namestringThe name of the health check to execute.
cancellationTokenCancellationTokenThe cancellation token.
Returns
- Task<HealthCheckResult>
The health check result, or null if the health check is not found.
CheckHealthAsync(CancellationToken)
Executes all registered health checks asynchronously.
public Task<IReadOnlyDictionary<string, HealthCheckResult>> CheckHealthAsync(CancellationToken cancellationToken = default)
Parameters
cancellationTokenCancellationTokenThe cancellation token.
Returns
- Task<IReadOnlyDictionary<string, HealthCheckResult>>
A dictionary containing the results of all health checks.
Exceptions
- ObjectDisposedException
Thrown when the service has been disposed.
Dispose()
Disposes the health check service and releases all resources.
public void Dispose()
RegisterHealthCheck(IHealthCheck)
Registers a health check with the service.
public void RegisterHealthCheck(IHealthCheck healthCheck)
Parameters
healthCheckIHealthCheckThe health check to register.
Exceptions
- ArgumentNullException
Thrown when healthCheck is null.
- ObjectDisposedException
Thrown when the service has been disposed.
UnregisterHealthCheck(string)
Unregisters a health check from the service.
public bool UnregisterHealthCheck(string name)
Parameters
namestringThe name of the health check to remove.
Returns
- bool
True if the health check was removed; otherwise, false.