Skip to main content

Cron

Struct Cron 

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

Fluent builder for a 5-field cron expression with optional time-of-day filters and a timezone.

Implementations§

Source§

impl Cron

Source

pub fn new() -> Self

Create a new builder initialised to "* * * * *" (every minute) in UTC.

Source

pub fn expression(&self) -> &str

The current cron expression.

Source

pub const fn repeat_seconds(&self) -> u32

The sub-minute repeat interval in seconds, or 0 if none is configured.

Set by Cron::every_second and its siblings.

Source

pub fn filters_pass(&self) -> bool

Evaluate all registered filters: returns true if every when filter returns true and no skip filter returns true.

Source

pub fn cron(&mut self, expression: &str) -> &mut Self

Set the raw cron expression.

Source

pub fn when<F: Fn() -> bool + Send + Sync + 'static>( &mut self, filter: F, ) -> &mut Self

Register a filter; the event runs only when every when filter returns true.

Source

pub fn skip<F: Fn() -> bool + Send + Sync + 'static>( &mut self, filter: F, ) -> &mut Self

Register a reject filter; the event is skipped whenever any skip filter returns true.

Source

pub fn between(&mut self, start_time: &str, end_time: &str) -> &mut Self

Schedule the event to run only between two times of day (e.g. "09:00", "17:00").

Times are parsed as HH:MM[:SS]. Windows that cross midnight (end < start) are handled by rolling one side to the adjacent day.

Source

pub fn unless_between(&mut self, start_time: &str, end_time: &str) -> &mut Self

Schedule the event to run except between two times of day.

The inverse of Cron::between.

Source

pub fn every_second(&mut self) -> &mut Self

Schedule the event to run every second.

Source

pub fn every_two_seconds(&mut self) -> &mut Self

Schedule the event to run every two seconds.

Source

pub fn every_five_seconds(&mut self) -> &mut Self

Schedule the event to run every five seconds.

Source

pub fn every_ten_seconds(&mut self) -> &mut Self

Schedule the event to run every ten seconds.

Source

pub fn every_fifteen_seconds(&mut self) -> &mut Self

Schedule the event to run every fifteen seconds.

Source

pub fn every_twenty_seconds(&mut self) -> &mut Self

Schedule the event to run every twenty seconds.

Source

pub fn every_thirty_seconds(&mut self) -> &mut Self

Schedule the event to run every thirty seconds.

Source

pub fn every_minute(&mut self) -> &mut Self

Schedule the event to run every minute.

Source

pub fn every_two_minutes(&mut self) -> &mut Self

Schedule the event to run every two minutes.

Source

pub fn every_three_minutes(&mut self) -> &mut Self

Schedule the event to run every three minutes.

Source

pub fn every_four_minutes(&mut self) -> &mut Self

Schedule the event to run every four minutes.

Source

pub fn every_five_minutes(&mut self) -> &mut Self

Schedule the event to run every five minutes.

Source

pub fn every_ten_minutes(&mut self) -> &mut Self

Schedule the event to run every ten minutes.

Source

pub fn every_fifteen_minutes(&mut self) -> &mut Self

Schedule the event to run every fifteen minutes.

Source

pub fn every_thirty_minutes(&mut self) -> &mut Self

Schedule the event to run every thirty minutes.

Source

pub fn hourly(&mut self) -> &mut Self

Schedule the event to run hourly (at minute 0).

Source

pub fn hourly_at(&mut self, offset: impl IntoCronValue) -> &mut Self

Schedule the event to run hourly at a given offset (a minute, list, or pattern) in the hour.

Source

pub fn every_odd_hour(&mut self) -> &mut Self

Schedule the event to run every odd hour.

Source

pub fn every_odd_hour_at(&mut self, offset: impl IntoCronValue) -> &mut Self

Schedule the event to run every odd hour at a given minute offset.

Source

pub fn every_two_hours(&mut self) -> &mut Self

Schedule the event to run every two hours.

Source

pub fn every_two_hours_at(&mut self, offset: impl IntoCronValue) -> &mut Self

Schedule the event to run every two hours at a given minute offset.

Source

pub fn every_three_hours(&mut self) -> &mut Self

Schedule the event to run every three hours.

Source

pub fn every_three_hours_at(&mut self, offset: impl IntoCronValue) -> &mut Self

Schedule the event to run every three hours at a given minute offset.

Source

pub fn every_four_hours(&mut self) -> &mut Self

Schedule the event to run every four hours.

Source

pub fn every_four_hours_at(&mut self, offset: impl IntoCronValue) -> &mut Self

Schedule the event to run every four hours at a given minute offset.

Source

pub fn every_six_hours(&mut self) -> &mut Self

Schedule the event to run every six hours.

Source

pub fn every_six_hours_at(&mut self, offset: impl IntoCronValue) -> &mut Self

Schedule the event to run every six hours at a given minute offset.

Source

pub fn daily(&mut self) -> &mut Self

Schedule the event to run daily at midnight.

Source

pub fn at(&mut self, time: &str) -> &mut Self

Alias for Cron::daily_at.

Source

pub fn daily_at(&mut self, time: &str) -> &mut Self

Schedule the event to run daily at a given time, formatted as HH:MM (e.g. "10:00", "19:30").

Seconds, if provided, are ignored.

Source

pub fn twice_daily(&mut self, first: u32, second: u32) -> &mut Self

Schedule the event to run twice daily at the given hours (minute 0).

Source

pub fn twice_daily_at( &mut self, first: u32, second: u32, offset: u32, ) -> &mut Self

Schedule the event to run twice daily at the given hours and minute offset.

Source

pub fn weekdays(&mut self) -> &mut Self

Schedule the event to run only on weekdays (Monday–Friday).

Source

pub fn weekends(&mut self) -> &mut Self

Schedule the event to run only on weekends (Saturday and Sunday).

Source

pub fn mondays(&mut self) -> &mut Self

Schedule the event to run only on Mondays.

Source

pub fn tuesdays(&mut self) -> &mut Self

Schedule the event to run only on Tuesdays.

Source

pub fn wednesdays(&mut self) -> &mut Self

Schedule the event to run only on Wednesdays.

Source

pub fn thursdays(&mut self) -> &mut Self

Schedule the event to run only on Thursdays.

Source

pub fn fridays(&mut self) -> &mut Self

Schedule the event to run only on Fridays.

Source

pub fn saturdays(&mut self) -> &mut Self

Schedule the event to run only on Saturdays.

Source

pub fn sundays(&mut self) -> &mut Self

Schedule the event to run only on Sundays.

Source

pub fn weekly(&mut self) -> &mut Self

Schedule the event to run weekly (Sundays at midnight).

Source

pub fn weekly_on( &mut self, day_of_week: impl IntoCronValue, time: &str, ) -> &mut Self

Schedule the event to run weekly on a given day and time.

Source

pub fn monthly(&mut self) -> &mut Self

Schedule the event to run monthly (first of the month at midnight).

Source

pub fn monthly_on(&mut self, day_of_month: u32, time: &str) -> &mut Self

Schedule the event to run monthly on a given day and time.

Source

pub fn twice_monthly(&mut self, first: u32, second: u32) -> &mut Self

Schedule the event to run twice monthly on the given days at midnight.

Source

pub fn twice_monthly_at( &mut self, first: u32, second: u32, time: &str, ) -> &mut Self

Schedule the event to run twice monthly on the given days at a given time.

Source

pub fn last_day_of_month(&mut self) -> &mut Self

Schedule the event to run on the last day of the month at midnight.

The last-day value is resolved against current time at build, so the resulting expression is anchored to the day-count of the current month (28–31).

Source

pub fn last_day_of_month_at(&mut self, time: &str) -> &mut Self

Schedule the event to run on the last day of the month at a given time.

See Cron::last_day_of_month for the caveat on when the day-of-month is resolved.

Source

pub fn days_of_month(&mut self, days: &[u32]) -> &mut Self

Schedule the event to run on specific days of the month at midnight.

Source

pub fn quarterly(&mut self) -> &mut Self

Schedule the event to run quarterly (first day of Jan, Apr, Jul, Oct at midnight).

Source

pub fn quarterly_on(&mut self, day_of_quarter: u32, time: &str) -> &mut Self

Schedule the event to run quarterly on a given day-of-quarter and time.

Source

pub fn yearly(&mut self) -> &mut Self

Schedule the event to run yearly (January 1st at midnight).

Source

pub fn yearly_on( &mut self, month: u32, day_of_month: impl IntoCronValue, time: &str, ) -> &mut Self

Schedule the event to run yearly on a given month, day, and time.

Source

pub fn days(&mut self, days: impl IntoCronValue) -> &mut Self

Set the days of the week the event should run on (the 5th cron field).

Source

pub const fn timezone(&mut self, timezone: Tz) -> &mut Self

Set the timezone the time-based filters (Cron::between, Cron::unless_between, Cron::last_day_of_month) are evaluated in.

Trait Implementations§

Source§

impl Default for Cron

Source§

fn default() -> Self

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

Auto Trait Implementations§

§

impl !RefUnwindSafe for Cron

§

impl !UnwindSafe for Cron

§

impl Forget for Cron

§

impl Freeze for Cron

§

impl Move for Cron

§

impl Send for Cron

§

impl Sync for Cron

§

impl Unpin for Cron

§

impl UnsafeUnpin for Cron

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> 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, 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.