pub fn offset(seed: &str, slot_start_unix: i64, max: Duration) -> DurationExpand description
Deterministic jitter offset in [0, max), derived from a stable hash of
(seed, slot_start_unix). NO RNG, NO clock.
seed should be a stable per-schedule key — the ADR specifies
BackupSchedule.UID (combined here with the slot’s wall-clock start). The same
(seed, slot_start, max) always yields the same Duration; different seeds or
slots spread across the window. max == 0 yields Duration::ZERO.
Resolution is whole seconds: jitter windows are minutes-to-hours, sub-second precision is meaningless for cron slots, and integer seconds keep the value trivially reproducible across languages if the mover ever re-derives it.
use std::time::Duration;
// Re-exported from the crate root as `jitter_offset`.
use kopiur_api::jitter_offset;
let max = Duration::from_secs(1800); // 30m window
// Deterministic: the same (seed, slot, max) always yields the same offset —
// HA replicas and restarts agree without coordination (ADR §4.1).
let a = jitter_offset("schedule-uid", 1_700_000_000, max);
let b = jitter_offset("schedule-uid", 1_700_000_000, max);
assert_eq!(a, b);
assert!(a < max);
// A zero window means no jitter.
assert_eq!(jitter_offset("uid", 123, Duration::ZERO), Duration::ZERO);