26 lines
998 B
C#
26 lines
998 B
C#
using System.Collections.Concurrent;
|
|
|
|
namespace w4c_workflows.Services.Triggers;
|
|
|
|
/// <summary>
|
|
/// 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).
|
|
/// </summary>
|
|
public sealed class InMemoryTriggerState : ITriggerState
|
|
{
|
|
private readonly ConcurrentDictionary<string, DateTimeOffset> _state = new();
|
|
|
|
public Task<DateTimeOffset?> 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;
|
|
}
|
|
} |