| | | 1 | | namespace AsiBackbone.AspNetCore.Outbox; |
| | | 2 | | |
| | | 3 | | /// <summary> |
| | | 4 | | /// Provides host-owned scheduling options for the governance 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> |
| | | 10 | | public sealed class AsiBackboneGovernanceOutboxDrainWorkerOptions |
| | | 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 remains alive and waits without creating scopes or resolving scoped store |
| | | 18 | | /// Re-enabling normally takes effect immediately through the options change notification, with the configured |
| | | 19 | | /// <see cref="PollingInterval" /> serving as a fallback observation interval. |
| | | 20 | | /// For multi-replica hosts, enable this only on the selected worker role or partition owner unless the outbox store |
| | | 21 | | /// provides host-owned claim/lease behavior before provider emission. |
| | | 22 | | /// </remarks> |
| | 113 | 23 | | public bool Enabled { get; set; } = true; |
| | | 24 | | |
| | | 25 | | /// <summary> |
| | | 26 | | /// Gets or sets the maximum number of pending or retry-ready entries attempted per drain pass. |
| | | 27 | | /// </summary> |
| | 148 | 28 | | public int BatchSize { get; set; } = 100; |
| | | 29 | | |
| | | 30 | | /// <summary> |
| | | 31 | | /// Gets or sets the interval between drain passes when the worker is enabled. |
| | | 32 | | /// </summary> |
| | | 33 | | /// <remarks> |
| | | 34 | | /// While the worker is disabled, this interval is also the fallback check period when the configured options source |
| | | 35 | | /// does not raise a change notification. |
| | | 36 | | /// </remarks> |
| | 156 | 37 | | public TimeSpan PollingInterval { get; set; } = TimeSpan.FromSeconds(30); |
| | | 38 | | |
| | | 39 | | /// <summary> |
| | | 40 | | /// Gets or sets the delay after an unexpected worker-level failure before the next drain pass is attempted. |
| | | 41 | | /// </summary> |
| | 120 | 42 | | public TimeSpan FailureDelay { get; set; } = TimeSpan.FromSeconds(30); |
| | | 43 | | |
| | | 44 | | /// <summary> |
| | | 45 | | /// Gets or sets the retry clock used when finding retry-ready entries. |
| | | 46 | | /// </summary> |
| | 133 | 47 | | public Func<DateTimeOffset> RetryClock { get; set; } = static () => DateTimeOffset.UtcNow; |
| | | 48 | | |
| | | 49 | | /// <summary> |
| | | 50 | | /// Gets or sets a value indicating whether a final drain pass should be attempted during host shutdown. |
| | | 51 | | /// </summary> |
| | | 52 | | /// <remarks> |
| | | 53 | | /// Avoid enabling shutdown drains on many replicas against the same durable outbox unless duplicate-emission behavi |
| | | 54 | | /// is controlled through partitioning, durable claiming, or provider-side idempotency. |
| | | 55 | | /// </remarks> |
| | 27 | 56 | | public bool DrainOnShutdown { get; set; } |
| | | 57 | | |
| | | 58 | | /// <summary> |
| | | 59 | | /// Gets or sets the maximum amount of time allowed for an optional shutdown drain pass. |
| | | 60 | | /// </summary> |
| | 122 | 61 | | public TimeSpan ShutdownDrainTimeout { get; set; } = TimeSpan.FromSeconds(5); |
| | | 62 | | |
| | | 63 | | /// <summary> |
| | | 64 | | /// Validates the configured worker options. |
| | | 65 | | /// </summary> |
| | | 66 | | /// <exception cref="InvalidOperationException">Thrown when a required worker option is invalid.</exception> |
| | | 67 | | public void Validate() |
| | | 68 | | { |
| | 43 | 69 | | if (BatchSize <= 0) |
| | | 70 | | { |
| | 4 | 71 | | throw new InvalidOperationException("Governance outbox drain batch size must be greater than zero."); |
| | | 72 | | } |
| | | 73 | | |
| | 39 | 74 | | if (PollingInterval <= TimeSpan.Zero) |
| | | 75 | | { |
| | 2 | 76 | | throw new InvalidOperationException("Governance outbox drain polling interval must be greater than zero."); |
| | | 77 | | } |
| | | 78 | | |
| | 37 | 79 | | if (FailureDelay <= TimeSpan.Zero) |
| | | 80 | | { |
| | 2 | 81 | | throw new InvalidOperationException("Governance outbox drain failure delay must be greater than zero."); |
| | | 82 | | } |
| | | 83 | | |
| | 35 | 84 | | if (ShutdownDrainTimeout <= TimeSpan.Zero) |
| | | 85 | | { |
| | 2 | 86 | | throw new InvalidOperationException("Governance outbox drain shutdown timeout must be greater than zero."); |
| | | 87 | | } |
| | | 88 | | |
| | 33 | 89 | | if (RetryClock is null) |
| | | 90 | | { |
| | 1 | 91 | | throw new InvalidOperationException("Governance outbox drain retry clock must be configured."); |
| | | 92 | | } |
| | 32 | 93 | | } |
| | | 94 | | } |