Skip to main content

Timings

Struct Timings 

Source
pub struct Timings {
    pub bind_grace: Duration,
    pub probe_timeout: Duration,
    pub join_timeout: Duration,
    pub busy_grace: Duration,
    pub read_deadline: Duration,
    pub idle: Duration,
}
Expand description

The timings above are the defaults. What a process actually judges a lease contest by is declared in .ai/repo/policy.yaml’s server: block and read once, here.

They were compiled constants until 2026-09-15: unchangeable without a rebuild, stated nowhere a reader would look, and invisible to every projection — while probe_timeout is the number that decides whether a live but slow owner keeps its lease or is taken over while it is still serving. That is a decision about how this repository is supervised, not an implementation detail, so it belongs in the model.

A OnceLock, because a process reads one policy: the repository is opened once and the answer must not change underneath a contest that is already being judged. Absent keys keep the constants, so a policy that cannot be read does not silently change behaviour.

use majordomus_cli::lease::{
    Timings, BIND_GRACE, BUSY_GRACE, IDLE, JOIN_TIMEOUT, PROBE_TIMEOUT, READ_DEADLINE,
};
// the defaults are the compiled constants, one for one
let t = Timings::default();
assert_eq!(t.bind_grace, BIND_GRACE);
assert_eq!(t.probe_timeout, PROBE_TIMEOUT);
assert_eq!(t.join_timeout, JOIN_TIMEOUT);
assert_eq!(t.busy_grace, BUSY_GRACE);
assert_eq!(t.read_deadline, READ_DEADLINE);
assert_eq!(t.idle, IDLE);
// a busy owner is given up on before the election that waits on it gives up itself
assert!(t.busy_grace < t.join_timeout);

Fields§

§bind_grace: Duration

server.bind_grace_seconds:

§probe_timeout: Duration

server.probe_timeout_seconds:

§join_timeout: Duration

server.join_timeout_seconds:

§busy_grace: Duration

server.busy_grace_seconds:

§read_deadline: Duration

server.read_deadline_seconds:

§idle: Duration

server.idle_seconds:

Implementations§

Source§

impl Timings

Source

pub fn from_policy(policy: &ServerPolicy) -> Self

What a declaration means, as a value rather than as a side effect.

The mapping is the part that can be wrong; the OnceLock below is plumbing. Kept separate so it can be tested directly — a test that went through the lock would depend on which test ran first, since a process reads one policy by construction.

use majordomus_cli::lease::Timings;
use majordomus_cli::policy::ServerPolicy;
use std::time::Duration;

// an empty declaration keeps every default
assert_eq!(Timings::from_policy(&ServerPolicy::default()), Timings::default());

// and a declared value is the one used, rather than the constant
let declared = ServerPolicy {
    probe_timeout_seconds: Some(9),
    ..ServerPolicy::default()
};
let t = Timings::from_policy(&declared);
assert_eq!(t.probe_timeout, Duration::from_secs(9));
assert_ne!(t.probe_timeout, Timings::default().probe_timeout);
// the keys it says nothing about are untouched
assert_eq!(t.bind_grace, Timings::default().bind_grace);

// the idle timeout is declared beside the others (I2701)
let declared = ServerPolicy { idle_seconds: Some(3), ..ServerPolicy::default() };
assert_eq!(Timings::from_policy(&declared).idle, Duration::from_secs(3));

Trait Implementations§

Source§

impl Clone for Timings

Source§

fn clone(&self) -> Timings

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 Timings

Source§

impl Debug for Timings

Source§

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

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

impl Default for Timings

Source§

fn default() -> Self

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

impl Eq for Timings

Source§

impl PartialEq for Timings

Source§

fn eq(&self, other: &Timings) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl StructuralPartialEq for Timings

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 ()

§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
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