fix(purge): short first tick on all three purge timers so daily-recycled nodes still purge

This commit is contained in:
Joseph Doherty
2026-07-09 09:26:42 -04:00
parent 7cd62933a6
commit b58d810dbe
5 changed files with 89 additions and 5 deletions
@@ -0,0 +1,33 @@
namespace ZB.MOM.WW.ScadaBridge.Commons.Types;
/// <summary>
/// Shared initial-delay rule for the central retention-purge singletons
/// (Audit Log partition purge, Site Call Audit terminal purge, KPI History
/// sample purge). All three run on a long (up to 24 h) interval; scheduling the
/// FIRST tick after a full interval meant a node that recycles more often than
/// the interval — e.g. a daily container restart against a 24 h cadence — would
/// never actually purge (arch-review 04, S9).
/// </summary>
/// <remarks>
/// Purges are idempotent, so an early first sweep is always safe. Taking
/// <c>min(interval, <see cref="ShortFirstTick"/>)</c> guarantees the first purge
/// runs within five minutes of startup while leaving the steady-state cadence —
/// and the millisecond intervals the actor test suites use — unchanged.
/// </remarks>
public static class PurgeTimerSchedule
{
/// <summary>
/// Upper bound on the delay before the first purge tick. Short enough that a
/// frequently-recycled node still purges, long enough not to add startup churn.
/// </summary>
public static readonly TimeSpan ShortFirstTick = TimeSpan.FromMinutes(5);
/// <summary>
/// The initial delay a purge timer should use for its first tick given its
/// steady-state <paramref name="interval"/>: the interval itself when it is
/// already shorter than <see cref="ShortFirstTick"/> (preserving fast test
/// cadences), otherwise capped at <see cref="ShortFirstTick"/>.
/// </summary>
public static TimeSpan InitialDelay(TimeSpan interval) =>
interval < ShortFirstTick ? interval : ShortFirstTick;
}