using System.Collections.Concurrent; namespace w4c_workflows.Services.Triggers; /// /// In-memory trigger state for lite/self-hosted mode where Redis is not available. /// Survives only for the process lifetime (restart = re-fire once, which is safe /// because delivery is at-least-once and the run lifecycle dedups via correlation id). /// public sealed class InMemoryTriggerState : ITriggerState { private readonly ConcurrentDictionary _state = new(); public Task GetLastFireAsync(string tenantId, Guid workflowId, CancellationToken ct) { var key = $"{tenantId}:{workflowId}"; return Task.FromResult(_state.TryGetValue(key, out var ts) ? (DateTimeOffset?)ts : null); } public Task SetLastFireAsync(string tenantId, Guid workflowId, DateTimeOffset at, CancellationToken ct) { var key = $"{tenantId}:{workflowId}"; _state[key] = at; return Task.CompletedTask; } }