Table of Contents

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

logger IWorkflowForgeLogger

The logger to use for health check operations.

timeProvider ISystemTimeProvider

The time provider to use for timestamps.

checkInterval TimeSpan?

The interval for periodic health checks. Set to null to disable periodic checks.

registerBuiltInHealthChecks bool

Whether 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

IReadOnlyDictionary<string, HealthCheckResult>

OverallStatus

Gets the overall health status based on the last check results.

public HealthStatus OverallStatus { get; }

Property Value

HealthStatus

Methods

CheckHealthAsync(string, CancellationToken)

Executes a specific health check by name.

public Task<HealthCheckResult?> CheckHealthAsync(string name, CancellationToken cancellationToken = default)

Parameters

name string

The name of the health check to execute.

cancellationToken CancellationToken

The 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

cancellationToken CancellationToken

The 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

healthCheck IHealthCheck

The 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

name string

The name of the health check to remove.

Returns

bool

True if the health check was removed; otherwise, false.