Skip to main content

effective_schedule_jitter

Function effective_schedule_jitter 

Source
pub fn effective_schedule_jitter(
    own: Option<&str>,
    candidates: &[Option<String>],
) -> Option<String>
Expand description

Pure. Decide the effective jitter window for a SnapshotSchedule, given the schedule’s own spec.schedule.jitter (own) and the scheduleDefaults.jitter of each matched target policy’s repository (candidates, one entry per matched policy; None = that repo sets no default).

The jitter counterpart of effective_timezone, and deliberately the same fan-out shape — but it returns a bare Option<String> rather than a (value, ambiguity) pair, because there is no fallback value to report an ambiguity against: disagreement resolves to “no jitter”, which is exactly what None already means. The caller logs the warn; this function just resolves.

Rules (the reconciler does the GETs and passes the data in):

  • own set → that window wins, no lookups.
  • own unset, no matched policies → None.
  • own unset, all matched policies agree → that value (which may itself be None, i.e. no repo sets a default).
  • own unset, matched policies disagree → None (no jitter). Mixing “a window” with “no default” is a genuine disagreement, same as effective_timezone.

A single policyRef therefore never disagrees (one repository).

use kopiur_api::common::effective_schedule_jitter;

// Own jitter wins outright.
assert_eq!(effective_schedule_jitter(Some("5m"), &[]).as_deref(), Some("5m"));

// Unset own, one agreeing default across matched policies.
let defs = [Some("1h".to_string()), Some("1h".to_string())];
assert_eq!(effective_schedule_jitter(None, &defs).as_deref(), Some("1h"));

// Unset own, disagreeing defaults → no jitter.
let defs = [Some("1h".to_string()), None];
assert_eq!(effective_schedule_jitter(None, &defs), None);