using Elsa.Workflows.Runtime.HealthChecks; using Elsa.Workflows.Runtime.Options; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Diagnostics.HealthChecks; namespace Elsa.Extensions; /// /// Adds Elsa workflow runtime readiness checks to ASP.NET Core health checks. /// public static class HealthCheckExtensions { /// /// Tag applied to Elsa readiness checks. /// public const string ReadinessTag = "readiness"; private static readonly string[] ReadinessTags = ["elsa", ReadinessTag]; /// /// Adds conservative Elsa-specific readiness probes for the workflow runtime and its core stores. /// /// The health checks builder. /// Whether to probe workflow management/runtime stores. /// Whether to probe the configured distributed lock provider. /// Configures Elsa readiness probe behavior. public static IHealthChecksBuilder AddElsaReadinessChecks( this IHealthChecksBuilder builder, bool includePersistence = true, bool includeDistributedLocks = false, Action? configureOptions = null) { var optionsBuilder = builder.Services.AddOptions(); if (configureOptions != null) optionsBuilder.Configure(configureOptions); builder.AddCheck("elsa-runtime", tags: ReadinessTags); if (includePersistence) builder.AddCheck("elsa-workflow-persistence", tags: ReadinessTags); if (includeDistributedLocks) builder.AddCheck("elsa-distributed-locks", tags: ReadinessTags); return builder; } }