Files
register-referentie/services/domain/Big.Application/HerregistratieReminderSweep.cs
T

31 lines
1.4 KiB
C#

using Big.Domain;
namespace Big.Application;
/// <summary>
/// The herregistratie reminder sweep (S-17): find the inscriptions whose herregistratie deadline is
/// within the reminder window and have not yet been reminded, mark each reminded, and persist it. Pure
/// application logic over ports — it knows nothing of Quartz; the scheduled job that fires it on a cron
/// lives in Infrastructure (mirroring how the pumps' processors are pure and the pump is the shell).
/// Idempotent: <see cref="Registration.MarkHerregistratieReminderVerstuurd"/> drops an inscription from
/// the next sweep's candidate set, so a re-fire reminds no one twice. Returns the reminded ids so the
/// caller can observe the sweep's effect — the reminder itself is the flag persisted on the aggregate.
/// </summary>
public sealed class HerregistratieReminderSweep(IRegistrationStore store, TimeProvider clock)
{
public async Task<IReadOnlyList<RegistrationId>> SweepAsync(CancellationToken ct = default)
{
var due = await store.FindDueForHerregistratieReminderAsync(clock.GetUtcNow(), ct);
var reminded = new List<RegistrationId>(due.Count);
foreach (var registration in due)
{
registration.MarkHerregistratieReminderVerstuurd();
await store.SaveAsync(registration, ct);
reminded.Add(registration.Id);
}
return reminded;
}
}