2026-05-20 11:34:25 +00:00
|
|
|
using Elsa.Workflows.Runtime.HealthChecks;
|
2026-05-20 22:09:46 +00:00
|
|
|
using Elsa.Workflows.Runtime.Options;
|
2026-05-20 11:34:25 +00:00
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
|
|
using Microsoft.Extensions.Diagnostics.HealthChecks;
|
|
|
|
|
|
|
|
|
|
namespace Elsa.Extensions;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Adds Elsa workflow runtime readiness checks to ASP.NET Core health checks.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public static class HealthCheckExtensions
|
|
|
|
|
{
|
2026-05-20 22:09:46 +00:00
|
|
|
/// <summary>
|
|
|
|
|
/// Tag applied to Elsa readiness checks.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public const string ReadinessTag = "readiness";
|
|
|
|
|
|
|
|
|
|
private static readonly string[] ReadinessTags = ["elsa", ReadinessTag];
|
2026-05-20 11:34:25 +00:00
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Adds conservative Elsa-specific readiness probes for the workflow runtime and its core stores.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="builder">The health checks builder.</param>
|
|
|
|
|
/// <param name="includePersistence">Whether to probe workflow management/runtime stores.</param>
|
|
|
|
|
/// <param name="includeDistributedLocks">Whether to probe the configured distributed lock provider.</param>
|
2026-05-20 22:09:46 +00:00
|
|
|
/// <param name="configureOptions">Configures Elsa readiness probe behavior.</param>
|
2026-05-20 11:34:25 +00:00
|
|
|
public static IHealthChecksBuilder AddElsaReadinessChecks(
|
|
|
|
|
this IHealthChecksBuilder builder,
|
|
|
|
|
bool includePersistence = true,
|
2026-05-20 22:09:46 +00:00
|
|
|
bool includeDistributedLocks = false,
|
|
|
|
|
Action<ElsaReadinessHealthCheckOptions>? configureOptions = null)
|
2026-05-20 11:34:25 +00:00
|
|
|
{
|
2026-05-20 22:09:46 +00:00
|
|
|
if (configureOptions != null)
|
|
|
|
|
builder.Services.Configure(configureOptions);
|
|
|
|
|
|
2026-05-20 11:34:25 +00:00
|
|
|
builder.AddCheck<ElsaRuntimeHealthCheck>("elsa-runtime", tags: ReadinessTags);
|
|
|
|
|
|
|
|
|
|
if (includePersistence)
|
|
|
|
|
builder.AddCheck<ElsaWorkflowPersistenceHealthCheck>("elsa-workflow-persistence", tags: ReadinessTags);
|
|
|
|
|
|
|
|
|
|
if (includeDistributedLocks)
|
|
|
|
|
builder.AddCheck<ElsaDistributedLockHealthCheck>("elsa-distributed-locks", tags: ReadinessTags);
|
|
|
|
|
|
|
|
|
|
return builder;
|
|
|
|
|
}
|
|
|
|
|
}
|