Skip to main content

Schedule

Struct Schedule 

Source
pub struct Schedule { /* private fields */ }
Expand description

An installation’s schedule.

§Examples

use stratum_node_core::{Schedule, UnixTime};

// Activated at 1000 s with a 300 s interval: the anchor is 900.
let s = Schedule::new(300, UnixTime::from_secs(1_000))?;
assert_eq!(s.anchor().map(UnixTime::as_secs), Some(900));
assert_eq!(
    s.period_bounds(0).map(|(a, b)| (a.as_secs(), b.as_secs())),
    Some((900, 1_200)),
);
assert_eq!(s.latest_ended(UnixTime::from_secs(1_199)), None);
assert_eq!(s.latest_ended(UnixTime::from_secs(1_200)), Some(0));
assert_eq!(s.latest_ended(UnixTime::from_secs(2_100)), Some(3));

// Nothing ran yet: run period 3, skip 0..3.
let due = s.ended_periods(None, UnixTime::from_secs(2_100)).ok_or("due")?;
assert_eq!((due.run, due.skip), (3, 0..3));

// Manual only: no period ever ends by itself.
let manual = Schedule::new(0, UnixTime::from_secs(1_000))?;
assert!(manual.is_manual());
assert_eq!(manual.latest_ended(UnixTime::from_secs(u64::MAX)), None);
assert!(Schedule::new(299, UnixTime::from_secs(0)).is_err());

Implementations§

Source§

impl Schedule

Source

pub fn new( schedule_secs: u64, activated_at: UnixTime, ) -> Result<Self, ScheduleError>

Builds the schedule of an installation activated at activated_at.

§Errors

ScheduleError when schedule_secs is neither 0 nor in 300..=604800.

Source

pub fn is_manual(&self) -> bool

Returns true for a manual-only schedule (schedule_secs 0).

Source

pub fn interval_secs(&self) -> Option<u64>

Returns the interval in seconds, or None when manual.

Source

pub fn anchor(&self) -> Option<UnixTime>

Returns the anchor, or None when manual.

Source

pub fn period_bounds(&self, n: u64) -> Option<(UnixTime, UnixTime)>

Returns the start and end of period n, [start, end), or None when manual or when the end would not fit in a u64.

Source

pub fn latest_ended(&self, now: UnixTime) -> Option<u64>

Returns the latest period that has ended at now, or None when manual or when no period has ended yet.

Source

pub fn ended_periods( &self, last_seen: Option<u64>, now: UnixTime, ) -> Option<EndedPeriods>

Returns what the scheduler does at now, given the latest period that already has a job (last_seen, None if none has): the period to run and the earlier ended periods to record skipped. None when no period after last_seen has ended.

Trait Implementations§

Source§

impl Clone for Schedule

Source§

fn clone(&self) -> Self

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 Schedule

Source§

impl Debug for Schedule

Source§

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

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

impl Eq for Schedule

Source§

impl Hash for Schedule

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for Schedule

Source§

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

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for Schedule

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
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
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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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.

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 = !

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

fn try_from(value: U) -> Result<T, !>

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.