< Summary

Information
Class: Elsa.Extensions.HealthCheckExtensions
Assembly: Elsa.Workflows.Runtime
File(s): /home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Workflows.Runtime/Extensions/HealthCheckExtensions.cs
Line coverage
100%
Covered lines: 13
Uncovered lines: 0
Coverable lines: 13
Total lines: 57
Line coverage: 100%
Branch coverage
100%
Covered branches: 6
Total branches: 6
Branch coverage: 100%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.cctor()100%11100%
AddElsaReadinessChecks(...)83.33%6691.66%

File(s)

/home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Workflows.Runtime/Extensions/HealthCheckExtensions.cs

#LineLine coverage
 1using Elsa.Workflows.Runtime.HealthChecks;
 2using Elsa.Workflows.Runtime.Options;
 3using Microsoft.Extensions.DependencyInjection;
 4using Microsoft.Extensions.Diagnostics.HealthChecks;
 5
 6namespace Elsa.Extensions;
 7
 8/// <summary>
 9/// Adds Elsa workflow runtime readiness checks to ASP.NET Core health checks.
 10/// </summary>
 11public static class HealthCheckExtensions
 12{
 13    /// <summary>
 14    /// Tag applied to Elsa health checks.
 15    /// </summary>
 16    public const string ElsaTag = "elsa";
 17
 18    /// <summary>
 19    /// Tag applied to Elsa readiness checks.
 20    /// </summary>
 21    public const string ReadinessTag = "elsa-readiness";
 22
 223    private static readonly string[] ReadinessTags = [ElsaTag, ReadinessTag];
 24
 25    /// <summary>
 26    /// Adds conservative Elsa-specific readiness probes for the workflow runtime and its core stores.
 27    /// </summary>
 28    /// <param name="builder">The health checks builder.</param>
 29    /// <param name="includePersistence">Whether to probe workflow management/runtime stores.</param>
 30    /// <param name="includeDistributedLocks">Whether to probe the configured distributed lock provider.</param>
 31    /// <param name="configureOptions">Configures Elsa readiness probe behavior.</param>
 32    public static IHealthChecksBuilder AddElsaReadinessChecks(
 33        this IHealthChecksBuilder builder,
 34        bool includePersistence = true,
 35        bool includeDistributedLocks = false,
 36        Action<ElsaReadinessHealthCheckOptions>? configureOptions = null)
 37    {
 738        var optionsBuilder = builder.Services.AddOptions<ElsaReadinessHealthCheckOptions>();
 39
 740        if (configureOptions != null)
 241            optionsBuilder.Configure(configureOptions);
 42
 743        optionsBuilder
 544            .Validate(x => x.DistributedLockAcquisitionTimeout > TimeSpan.Zero, "Distributed lock acquisition timeout mu
 745            .ValidateOnStart();
 46
 747        builder.AddCheck<ElsaRuntimeHealthCheck>("elsa-runtime", tags: ReadinessTags);
 48
 749        if (includePersistence)
 350            builder.AddCheck<ElsaWorkflowPersistenceHealthCheck>("elsa-workflow-persistence", tags: ReadinessTags);
 51
 752        if (includeDistributedLocks)
 653            builder.AddCheck<ElsaDistributedLockHealthCheck>("elsa-distributed-locks", tags: ReadinessTags);
 54
 755        return builder;
 56    }
 57}