| | | 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 | | /// For multi-replica hosts, enable this only on the selected worker role or partition owner unless the outbox store |
| | | 17 | | /// provides host-owned claim/lease behavior before provider emission. |
| | | 18 | | /// </remarks> |
| | 52 | 19 | | public bool Enabled { get; set; } = true; |
| | | 20 | | |
| | | 21 | | /// <summary> |
| | | 22 | | /// Gets or sets the maximum number of pending or retry-ready entries attempted per drain pass. |
| | | 23 | | /// </summary> |
| | 82 | 24 | | public int BatchSize { get; set; } = 100; |
| | | 25 | | |
| | | 26 | | /// <summary> |
| | | 27 | | /// Gets or sets the interval between drain passes when the worker is enabled. |
| | | 28 | | /// </summary> |
| | 80 | 29 | | public TimeSpan PollingInterval { get; set; } = TimeSpan.FromSeconds(30); |
| | | 30 | | |
| | | 31 | | /// <summary> |
| | | 32 | | /// Gets or sets the delay after an unexpected worker-level failure before the next drain pass is attempted. |
| | | 33 | | /// </summary> |
| | 52 | 34 | | public TimeSpan FailureDelay { get; set; } = TimeSpan.FromSeconds(30); |
| | | 35 | | |
| | | 36 | | /// <summary> |
| | | 37 | | /// Gets or sets the retry clock used when finding retry-ready entries. |
| | | 38 | | /// </summary> |
| | 76 | 39 | | public Func<DateTimeOffset> RetryClock { get; set; } = static () => DateTimeOffset.UtcNow; |
| | | 40 | | |
| | | 41 | | /// <summary> |
| | | 42 | | /// Gets or sets a value indicating whether a final drain pass should be attempted during host shutdown. |
| | | 43 | | /// </summary> |
| | | 44 | | /// <remarks> |
| | | 45 | | /// Avoid enabling shutdown drains on many replicas against the same durable outbox unless duplicate-emission behavi |
| | | 46 | | /// is controlled through partitioning, durable claiming, or provider-side idempotency. |
| | | 47 | | /// </remarks> |
| | 10 | 48 | | public bool DrainOnShutdown { get; set; } |
| | | 49 | | |
| | | 50 | | /// <summary> |
| | | 51 | | /// Gets or sets the maximum amount of time allowed for an optional shutdown drain pass. |
| | | 52 | | /// </summary> |
| | 58 | 53 | | public TimeSpan ShutdownDrainTimeout { get; set; } = TimeSpan.FromSeconds(5); |
| | | 54 | | |
| | | 55 | | /// <summary> |
| | | 56 | | /// Validates the configured worker options. |
| | | 57 | | /// </summary> |
| | | 58 | | /// <exception cref="InvalidOperationException">Thrown when a required worker option is invalid.</exception> |
| | | 59 | | public void Validate() |
| | | 60 | | { |
| | 32 | 61 | | if (BatchSize <= 0) |
| | | 62 | | { |
| | 4 | 63 | | throw new InvalidOperationException("Governance outbox drain batch size must be greater than zero."); |
| | | 64 | | } |
| | | 65 | | |
| | 28 | 66 | | if (PollingInterval <= TimeSpan.Zero) |
| | | 67 | | { |
| | 0 | 68 | | throw new InvalidOperationException("Governance outbox drain polling interval must be greater than zero."); |
| | | 69 | | } |
| | | 70 | | |
| | 28 | 71 | | if (FailureDelay <= TimeSpan.Zero) |
| | | 72 | | { |
| | 0 | 73 | | throw new InvalidOperationException("Governance outbox drain failure delay must be greater than zero."); |
| | | 74 | | } |
| | | 75 | | |
| | 28 | 76 | | if (ShutdownDrainTimeout <= TimeSpan.Zero) |
| | | 77 | | { |
| | 0 | 78 | | throw new InvalidOperationException("Governance outbox drain shutdown timeout must be greater than zero."); |
| | | 79 | | } |
| | | 80 | | |
| | 28 | 81 | | if (RetryClock is null) |
| | | 82 | | { |
| | 0 | 83 | | throw new InvalidOperationException("Governance outbox drain retry clock must be configured."); |
| | | 84 | | } |
| | 28 | 85 | | } |
| | | 86 | | } |