Skip to main content

effective_jitter

Function effective_jitter 

Source
pub fn effective_jitter(
    own: Option<&str>,
    repo_default: Option<&str>,
) -> Option<String>
Expand description

Pure. Resolve a consuming cron’s own optional jitter against a repository-level scheduleDefaults.jitter: own wins when set, else repo_default, else None (no jitter). Mirrors resolve_tz_with_default’s shape for the timezone half of scheduleDefaults, minus a built-in fallback — there is no “default jitter”, absent simply means no spread.

The returned string is still the user’s raw text; the scheduler parses it with crate::duration::parse_go_duration exactly as it does an own-set value, and the admission webhook has already rejected an unparseable or over-24h value at BOTH levels (validate_jitter + validate_jitter_bounds).

use kopiur_api::common::effective_jitter;

// The schedule's own jitter wins, even over a repo default.
assert_eq!(effective_jitter(Some("5m"), Some("1h")).as_deref(), Some("5m"));
// Absent own jitter inherits the repo default.
assert_eq!(effective_jitter(None, Some("1h")).as_deref(), Some("1h"));
// Both absent → no jitter.
assert_eq!(effective_jitter(None, None), None);