pub struct CronSchedule { /* private fields */ }Expand description
A validated cron expression.
Internally wraps a croner::Cron, guaranteeing that the expression
has been parsed and validated at construction time.
as_str returns the original expression
as provided by the user, not the normalized form.
The schedule also carries a SchedulePolicy, set with the with_*
builder methods. The policy is not part of the serialized form: a
CronSchedule serializes to its raw expression, and deserializing one
gives the default policy.
§Examples
use ironflow_engine::schedule::CronSchedule;
let sched = CronSchedule::new("0 0 * * * *").unwrap();
assert_eq!(sched.as_str(), "0 0 * * * *");
let bad = CronSchedule::new("not a cron");
assert!(bad.is_err());Implementations§
Source§impl CronSchedule
impl CronSchedule
Sourcepub fn new(expression: &str) -> Result<Self, String>
pub fn new(expression: &str) -> Result<Self, String>
Parse and validate a cron expression.
Accepts 5-field (standard) or 6-field (with seconds) expressions,
as supported by croner.
§Errors
Returns an error string if the expression is syntactically invalid.
§Examples
use ironflow_engine::schedule::CronSchedule;
assert!(CronSchedule::new("0 */5 * * * *").is_ok());
assert!(CronSchedule::new("garbage").is_err());Sourcepub fn with_timezone(self, tz: &str) -> Result<Self, String>
pub fn with_timezone(self, tz: &str) -> Result<Self, String>
Evaluate the expression in an IANA timezone instead of UTC.
Occurrences follow the wall clock of the timezone across daylight
saving changes: 0 9 * * * in Europe/Paris fires at 9:00 Paris
time in winter and in summer. An occurrence in an hour skipped in
spring fires once at the end of the gap; an occurrence in an hour
repeated in autumn fires once, on its first pass.
§Errors
Returns an error string if tz is not a known IANA timezone name.
§Examples
use ironflow_engine::schedule::CronSchedule;
let sched = CronSchedule::new("0 9 * * *")?.with_timezone("Europe/Paris")?;
assert_eq!(sched.policy().timezone.name(), "Europe/Paris");
assert!(CronSchedule::new("0 9 * * *")?.with_timezone("Mars/Olympus").is_err());Sourcepub fn with_catchup(self, catchup: CatchupPolicy) -> Self
pub fn with_catchup(self, catchup: CatchupPolicy) -> Self
Set what the schedule does with the occurrences it missed while no
server fired it. Defaults to CatchupPolicy::Latest.
§Examples
use ironflow_engine::schedule::{CronSchedule, CatchupPolicy};
let sched = CronSchedule::new("0 * * * *")?.with_catchup(CatchupPolicy::All);
assert_eq!(sched.policy().catchup, CatchupPolicy::All);Sourcepub fn with_catchup_max(self, max: u32) -> Self
pub fn with_catchup_max(self, max: u32) -> Self
Set the most runs created to catch up under CatchupPolicy::All.
The most recent missed occurrences are kept. Defaults to 10.
§Panics
Panics if max is not between 1 and 1000.
§Examples
use ironflow_engine::schedule::CronSchedule;
let sched = CronSchedule::new("0 * * * *")?.with_catchup_max(24);
assert_eq!(sched.policy().catchup_max, 24);Sourcepub fn with_catchup_window(self, window: Duration) -> Self
pub fn with_catchup_window(self, window: Duration) -> Self
Set how far back a missed occurrence is still caught up. Older ones are dropped. Defaults to one day.
§Panics
Panics if window is shorter than one minute or longer than 30 days.
§Examples
use std::time::Duration;
use ironflow_engine::schedule::CronSchedule;
let sched = CronSchedule::new("0 * * * *")?.with_catchup_window(Duration::from_secs(6 * 3600));
assert_eq!(sched.policy().catchup_window_secs, 21_600);Sourcepub fn with_overlap(self, overlap: OverlapPolicy) -> Self
pub fn with_overlap(self, overlap: OverlapPolicy) -> Self
Set what the schedule does when an occurrence comes while one of its
runs is still active. Defaults to OverlapPolicy::Allow.
§Examples
use ironflow_engine::schedule::{CronSchedule, OverlapPolicy};
let sched = CronSchedule::new("*/5 * * * *")?.with_overlap(OverlapPolicy::Skip);
assert_eq!(sched.policy().overlap, OverlapPolicy::Skip);Sourcepub fn policy(&self) -> &SchedulePolicy
pub fn policy(&self) -> &SchedulePolicy
Returns the catch-up, overlap and timezone policy of the schedule.
§Examples
use ironflow_engine::schedule::{CronSchedule, SchedulePolicy};
let sched = CronSchedule::new("0 * * * *")?;
assert_eq!(sched.policy(), &SchedulePolicy::default());Trait Implementations§
Source§impl Clone for CronSchedule
impl Clone for CronSchedule
Source§impl Debug for CronSchedule
impl Debug for CronSchedule
Source§impl<'de> Deserialize<'de> for CronSchedule
impl<'de> Deserialize<'de> for CronSchedule
Source§fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
Source§impl Display for CronSchedule
impl Display for CronSchedule
impl Eq for CronSchedule
Source§impl PartialEq for CronSchedule
impl PartialEq for CronSchedule
Auto Trait Implementations§
impl Freeze for CronSchedule
impl RefUnwindSafe for CronSchedule
impl Send for CronSchedule
impl Sync for CronSchedule
impl Unpin for CronSchedule
impl UnsafeUnpin for CronSchedule
impl UnwindSafe for CronSchedule
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.