| | | 1 | | namespace AsiBackbone.Core.Outbox; |
| | | 2 | | |
| | | 3 | | /// <summary> |
| | | 4 | | /// Describes an opt-in governance outbox claim and lease request. |
| | | 5 | | /// </summary> |
| | | 6 | | /// <remarks> |
| | | 7 | | /// Claim requests are used by claim-capable stores to coordinate scaled workers before provider emission. They do not c |
| | | 8 | | /// </remarks> |
| | | 9 | | public sealed class GovernanceOutboxClaimRequest |
| | | 10 | | { |
| | | 11 | | /// <summary> |
| | | 12 | | /// Gets the default lease duration for claimed outbox work. |
| | | 13 | | /// </summary> |
| | 5 | 14 | | public static readonly TimeSpan DefaultLeaseDuration = TimeSpan.FromMinutes(5); |
| | | 15 | | |
| | 174 | 16 | | private GovernanceOutboxClaimRequest( |
| | 174 | 17 | | string workerId, |
| | 174 | 18 | | DateTimeOffset utcNow, |
| | 174 | 19 | | TimeSpan leaseDuration, |
| | 174 | 20 | | int maxCount) |
| | | 21 | | { |
| | 174 | 22 | | ArgumentException.ThrowIfNullOrWhiteSpace(workerId); |
| | | 23 | | |
| | 172 | 24 | | if (leaseDuration <= TimeSpan.Zero) |
| | | 25 | | { |
| | 4 | 26 | | throw new ArgumentOutOfRangeException(nameof(leaseDuration), leaseDuration, "Lease duration must be greater |
| | | 27 | | } |
| | | 28 | | |
| | 168 | 29 | | if (maxCount <= 0) |
| | | 30 | | { |
| | 4 | 31 | | throw new ArgumentOutOfRangeException(nameof(maxCount), maxCount, "Maximum count must be greater than zero." |
| | | 32 | | } |
| | | 33 | | |
| | 164 | 34 | | WorkerId = workerId.Trim(); |
| | 164 | 35 | | UtcNow = utcNow.ToUniversalTime(); |
| | 164 | 36 | | LeaseDuration = leaseDuration; |
| | 164 | 37 | | MaxCount = maxCount; |
| | 164 | 38 | | } |
| | | 39 | | |
| | | 40 | | /// <summary> |
| | | 41 | | /// Gets the stable worker, process, node, or partition owner identifier requesting the claim. |
| | | 42 | | /// </summary> |
| | 440 | 43 | | public string WorkerId { get; } |
| | | 44 | | |
| | | 45 | | /// <summary> |
| | | 46 | | /// Gets the UTC timestamp used for eligibility and lease expiration calculations. |
| | | 47 | | /// </summary> |
| | 1426 | 48 | | public DateTimeOffset UtcNow { get; } |
| | | 49 | | |
| | | 50 | | /// <summary> |
| | | 51 | | /// Gets the requested claim lease duration. |
| | | 52 | | /// </summary> |
| | 442 | 53 | | public TimeSpan LeaseDuration { get; } |
| | | 54 | | |
| | | 55 | | /// <summary> |
| | | 56 | | /// Gets the maximum number of entries to claim. |
| | | 57 | | /// </summary> |
| | 668 | 58 | | public int MaxCount { get; } |
| | | 59 | | |
| | | 60 | | /// <summary> |
| | | 61 | | /// Gets the UTC timestamp at which the requested lease expires. |
| | | 62 | | /// </summary> |
| | 2 | 63 | | public DateTimeOffset ClaimExpiresUtc => UtcNow.Add(LeaseDuration); |
| | | 64 | | |
| | | 65 | | /// <summary> |
| | | 66 | | /// Creates a claim request with normalized worker and timing values. |
| | | 67 | | /// </summary> |
| | | 68 | | public static GovernanceOutboxClaimRequest Create( |
| | | 69 | | string workerId, |
| | | 70 | | DateTimeOffset? utcNow = null, |
| | | 71 | | TimeSpan? leaseDuration = null, |
| | | 72 | | int maxCount = 100) |
| | | 73 | | { |
| | 174 | 74 | | return new GovernanceOutboxClaimRequest( |
| | 174 | 75 | | workerId, |
| | 174 | 76 | | utcNow ?? DateTimeOffset.UtcNow, |
| | 174 | 77 | | leaseDuration ?? DefaultLeaseDuration, |
| | 174 | 78 | | maxCount); |
| | | 79 | | } |
| | | 80 | | } |