Skip to main content

Thresholds

Struct Thresholds 

Source
pub struct Thresholds {
    pub fresh_minutes: Option<i64>,
    pub stale_minutes: Option<i64>,
}
Expand description

The thresholds a record is judged against, read from session.freshness: of the policy and never defaulted here.

Both fields are Option because the policy is allowed to be silent, and the silence is carried rather than filled in: a constant in this file would be a second source of truth for a number the policy owns. So the default value of this type is not “judge nothing old” — it is “this repository has not said”, and Thresholds::judge answers Freshness::Unknown naming the missing key, which is a fact a reader can act on by declaring it.

use majordomus_cli::capability::builtin::continuity::{epoch_seconds, Freshness, Thresholds};

let then = epoch_seconds("2026-09-05T12:00:00Z").unwrap();

// undeclared: the age is still reported, and the verdict withholds itself
let (verdict, age, why) = Thresholds::default().judge("2026-09-05T12:00:00Z", then + 3600);
assert_eq!(verdict, Freshness::Unknown);
assert_eq!(age, Some(60), "the age is measurable without a threshold to judge it by");
assert!(why.contains("session.freshness"), "it names the key to declare: {why}");

// declared: the same record, now placed in a band
let policy = Thresholds { fresh_minutes: Some(30), stale_minutes: Some(240) };
let (verdict, _, _) = policy.judge("2026-09-05T12:00:00Z", then + 3600);
assert_eq!(verdict, Freshness::Aging);

Fields§

§fresh_minutes: Option<i64>

session.freshness.fresh_minutes.

§stale_minutes: Option<i64>

session.freshness.stale_minutes.

Implementations§

Source§

impl Thresholds

Source

pub fn judge( self, created_at: &str, now: i64, ) -> (Freshness, Option<i64>, String)

Judge one record’s created_at against these thresholds, at now (Unix seconds). Returns the verdict, the age in whole minutes when there is one, and the reason — which is never empty, because a verdict a reader cannot act on is the failure this whole subsystem is being corrected for.

Both bands are closed at the bottom: a record exactly fresh_minutes old is already aging, and one exactly stale_minutes old is already stale. now is a parameter rather than a clock read inside, which is what makes the judgement a pure function of two recorded facts and lets a test pin the instant.

The three ways there is nothing to judge are kept apart, because they call for different actions: no timestamp and no declared threshold are unknown — go and declare one — while a timestamp that does not parse, or one in the future, is invalid, which means a writer produced a record this reader should not trust.

use majordomus_cli::capability::builtin::continuity::{epoch_seconds, Freshness, Thresholds};

let policy = Thresholds { fresh_minutes: Some(30), stale_minutes: Some(240) };
let at = "2026-09-05T12:00:00Z";
let then = epoch_seconds(at).unwrap();
let verdict = |minutes: i64| policy.judge(at, then + minutes * 60).0;

// the bands, and the boundaries, which are closed at the bottom
assert_eq!(verdict(29), Freshness::Fresh);
assert_eq!(verdict(30), Freshness::Aging, "at the threshold it has already aged");
assert_eq!(verdict(239), Freshness::Aging);
assert_eq!(verdict(240), Freshness::Stale);

// the age comes back measured, and the reason says it in the tool's own words
let (_, age, why) = policy.judge(at, then + 1500 * 60);
assert_eq!(age, Some(1500));
assert!(why.contains("25h"), "spans read as the shell tool writes them: {why}");

// a record from the future is not old, it is wrong, and it says so
let (verdict, _, why) = policy.judge(at, then - 600);
assert_eq!(verdict, Freshness::Invalid);
assert!(why.contains("future"), "{why}");
assert_eq!(policy.judge("the day before", then).0, Freshness::Invalid);

// and nothing to judge at all is `unknown`, which is not a complaint about the record
assert_eq!(policy.judge("", then).0, Freshness::Unknown);

Trait Implementations§

Source§

impl Clone for Thresholds

Source§

fn clone(&self) -> Thresholds

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for Thresholds

Source§

impl Debug for Thresholds

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Thresholds

Source§

fn default() -> Thresholds

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

impl<T> AsOut<T> for T
where T: Copy,

§

fn as_out(&mut self) -> Out<'_, T>

Returns an out reference to self.
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more