< Summary

Information
Class: AsiBackbone.AspNetCore.Outbox.GovernanceOutboxDrainWorkerOptions
Assembly: AsiBackbone.AspNetCore
File(s): /home/runner/work/AsiBackbone/AsiBackbone/src/AsiBackbone.AspNetCore/Outbox/GovernanceOutboxDrainWorkerOptions.cs
Line coverage
100%
Covered lines: 12
Uncovered lines: 0
Coverable lines: 12
Total lines: 115
Line coverage: 100%
Branch coverage
100%
Covered branches: 10
Total branches: 10
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%
Validate()100%1010100%

File(s)

/home/runner/work/AsiBackbone/AsiBackbone/src/AsiBackbone.AspNetCore/Outbox/GovernanceOutboxDrainWorkerOptions.cs

#LineLine coverage
 1namespace AsiBackbone.AspNetCore.Outbox;
 2
 3/// <summary>
 4/// Provides host-owned scheduling options for the outbox drain worker.
 5/// </summary>
 6/// <remarks>
 7/// The hosted worker is local to the process in which it is registered. In horizontally scaled deployments, each
 8/// replica may run its own worker unless the host disables extra replicas, partitions work, or adds durable claiming.
 9/// </remarks>
 10public sealed class GovernanceOutboxDrainWorkerOptions
 11{
 12    /// <summary>
 13    /// Gets or sets a value indicating whether the hosted drain worker should run.
 14    /// </summary>
 15    /// <remarks>
 16    /// Runtime changes supplied through <c>IOptionsMonitor</c> pause or resume new drain cycles without restarting the
 17    /// process. A worker that starts disabled validates its scoped drain dependencies once, then remains alive and wait
 18    /// without starting drain cycles or retaining scoped services.
 19    /// Re-enabling normally takes effect immediately through the options change notification, with the configured
 20    /// <see cref="PollingInterval" /> serving as a fallback observation interval.
 21    /// For multi-replica hosts, enable this only on the selected worker role or partition owner unless the outbox store
 22    /// provides host-owned claim/lease behavior before provider emission.
 23    /// </remarks>
 24    public bool Enabled { get; set; } = true;
 25
 26    /// <summary>
 27    /// Gets or sets the maximum number of pending or retry-ready entries attempted per drain pass.
 28    /// </summary>
 29    public int BatchSize { get; set; } = 100;
 30
 31    /// <summary>
 32    /// Gets or sets the interval between drain passes when the worker is enabled.
 33    /// </summary>
 34    /// <remarks>
 35    /// While the worker is disabled, this interval is also the fallback check period when the configured options source
 36    /// does not raise a change notification.
 37    /// </remarks>
 38    public TimeSpan PollingInterval { get; set; } = TimeSpan.FromSeconds(30);
 39
 40    /// <summary>
 41    /// Gets or sets the delay after an unexpected worker-level failure before the next drain pass is attempted.
 42    /// </summary>
 43    public TimeSpan FailureDelay { get; set; } = TimeSpan.FromSeconds(30);
 44
 45    /// <summary>
 46    /// The default <see cref="RetryClock" /> value. The worker recognizes it by reference and reads the registered
 47    /// <see cref="TimeProvider" /> instead.
 48    /// </summary>
 149    internal static readonly Func<DateTimeOffset> DefaultRetryClock = static () => DateTimeOffset.UtcNow;
 50
 51    /// <summary>
 52    /// Obsolete. Gets or sets the legacy clock used to timestamp a hosted drain cycle.
 53    /// </summary>
 54    /// <remarks>
 55    /// Register a <see cref="TimeProvider" /> instead. While this property keeps its default value, the worker reads th
 56    /// registered provider and passes that timestamp to the drain. Assigning a custom delegate instead supplies the
 57    /// explicit timestamp for the whole drain cycle, including retry-ready checks, claim timing, and persisted drain
 58    /// transitions. Other <see cref="TimeProvider" /> consumers continue to read the registered provider and can theref
 59    /// disagree with the custom delegate. The warning remains non-error in the 7.x line; removal is planned for the nex
 60    /// permitted major version.
 61    /// </remarks>
 62    [Obsolete(
 63        "RetryClock bypasses the registered TimeProvider for the entire hosted drain cycle and can diverge from other Ti
 64        DiagnosticId = "ASIB903",
 65        UrlFormat = "https://asibackbone.github.io/AsiBackbone/articles/asib903-outbox-retry-clock.html")]
 66    public Func<DateTimeOffset> RetryClock { get; set; } = DefaultRetryClock;
 67
 68    /// <summary>
 69    /// Gets or sets a value indicating whether a final drain pass should be attempted during host shutdown.
 70    /// </summary>
 71    /// <remarks>
 72    /// Avoid enabling shutdown drains on many replicas against the same durable outbox unless duplicate-emission behavi
 73    /// is controlled through partitioning, durable claiming, or provider-side idempotency.
 74    /// </remarks>
 75    public bool DrainOnShutdown { get; set; }
 76
 77    /// <summary>
 78    /// Gets or sets the maximum amount of time allowed for an optional shutdown drain pass.
 79    /// </summary>
 80    public TimeSpan ShutdownDrainTimeout { get; set; } = TimeSpan.FromSeconds(5);
 81
 82    /// <summary>
 83    /// Validates the configured worker options.
 84    /// </summary>
 85    /// <exception cref="InvalidOperationException">Thrown when a required worker option is invalid.</exception>
 86    public void Validate()
 87    {
 5588        if (BatchSize <= 0)
 89        {
 490            throw new InvalidOperationException("Governance outbox drain batch size must be greater than zero.");
 91        }
 92
 5193        if (PollingInterval <= TimeSpan.Zero)
 94        {
 295            throw new InvalidOperationException("Governance outbox drain polling interval must be greater than zero.");
 96        }
 97
 4998        if (FailureDelay <= TimeSpan.Zero)
 99        {
 2100            throw new InvalidOperationException("Governance outbox drain failure delay must be greater than zero.");
 101        }
 102
 47103        if (ShutdownDrainTimeout <= TimeSpan.Zero)
 104        {
 2105            throw new InvalidOperationException("Governance outbox drain shutdown timeout must be greater than zero.");
 106        }
 107
 108#pragma warning disable ASIB903 // Validation keeps rejecting a null delegate while the obsolete property exists.
 45109        if (RetryClock is null)
 110        {
 1111            throw new InvalidOperationException("Governance outbox drain retry clock must be configured.");
 112        }
 113#pragma warning restore ASIB903
 44114    }
 115}

Methods/Properties

.cctor()
Validate()