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
impl Schedule
Sourcepub fn new(
schedule_secs: u64,
activated_at: UnixTime,
) -> Result<Self, ScheduleError>
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.
Sourcepub fn interval_secs(&self) -> Option<u64>
pub fn interval_secs(&self) -> Option<u64>
Returns the interval in seconds, or None when manual.
Sourcepub fn period_bounds(&self, n: u64) -> Option<(UnixTime, UnixTime)>
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.
Sourcepub fn latest_ended(&self, now: UnixTime) -> Option<u64>
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.
Sourcepub fn ended_periods(
&self,
last_seen: Option<u64>,
now: UnixTime,
) -> Option<EndedPeriods>
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§
impl Copy for Schedule
impl Eq for Schedule
impl StructuralPartialEq for Schedule
Auto Trait Implementations§
impl Forget for Schedule
impl Freeze for Schedule
impl Move for Schedule
impl RefUnwindSafe for Schedule
impl Send for Schedule
impl Sync for Schedule
impl Unpin for Schedule
impl UnsafeUnpin for Schedule
impl UnwindSafe for Schedule
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more