CronSchedule

Struct CronSchedule 

Source
pub struct CronSchedule<Z>
where Z: TimeZone,
{ /* private fields */ }
Expand description

A schedule that can be used to execute tasks using Celery’s crontab syntax.

§Examples

// Schedule a task every 5 minutes from Monday to Friday:
celery::beat::CronSchedule::from_string("*/5 * * * mon-fri");

// Schedule a task each minute from 8 am to 5 pm on the first day
// of every month but only if it is Sunday:
celery::beat::CronSchedule::from_string("* 8-17 1 * sun");

// Execute every minute in march with a custom time zone:
let time_zone = chrono::offset::FixedOffset::east(3600);
celery::beat::CronSchedule::from_string_with_time_zone("* * * mar *", time_zone);

A schedule can also be defined using vectors with the required candidates:

celery::beat::CronSchedule::new(
    vec![15,30,45,59,0],
    vec![0,23],
    vec![1,2,3],
    vec![1,2,3,4,12],
    (1..=6).collect(),
);

Implementations§

Source§

impl CronSchedule<Utc>

Source

pub fn new( minutes: Vec<u32>, hours: Vec<u32>, month_days: Vec<u32>, months: Vec<u32>, week_days: Vec<u32>, ) -> Result<Self, ScheduleError>

Create a new cron schedule which can be used to run a task in the specified minutes/hours/month days/week days/months. This schedule will use the UTC time zone.

No vector should be empty and each argument must be in the range of valid values for its respective time unit.

Source

pub fn from_string(schedule: &str) -> Result<Self, ScheduleError>

Create a cron schedule from a cron string. This schedule will use the UTC time zone.

The string must be a space-separated list of five elements, representing minutes, hours, month days, months and week days (in this order). Each element can be:

  • a number in the correct range for the given time unit: e.g. 3
  • a range: e.g. 2-5 which corresponds to 2,3,4,5
  • a range with a step: e.g. 1-6/3 which corresponds to 1,4
  • a wildcard: i.e. * which corresponds to all elements for the given time unit
  • a wildcard with a step: e.g. */4 which corresponds to one every four elements
  • a comma-separated list (without spaces) where each element is one of the previous ones: e.g. 8,2-4,1-5/2 which corresponds to 1,2,3,4,5,8

Months and week days can also be represented using the first three letters instead of numbers (e.g, mon, thu, may, oct…).

As an alternative, a shorthand representation can be used. The following options are available:

  • @yearly: at 0:00 on the first of January each year
  • @monthly: at 0:00 at the beginning of each month
  • @weekly: at 0:00 on Monday each week
  • @daily: at 0:00 each day
  • @hourly: each hour at 00
Source§

impl<Z> CronSchedule<Z>
where Z: TimeZone,

Source

pub fn new_with_time_zone( minutes: Vec<u32>, hours: Vec<u32>, month_days: Vec<u32>, months: Vec<u32>, week_days: Vec<u32>, time_zone: Z, ) -> Result<Self, ScheduleError>

Create a new cron schedule which can be used to run a task in the specified minutes/hours/month days/week days/months. This schedule will use the given time zone.

No vector should be empty and each argument must be in the range of valid values for its respective time unit.

Source

pub fn from_string_with_time_zone( schedule: &str, time_zone: Z, ) -> Result<Self, ScheduleError>

Create a cron schedule from a cron string. This schedule will use the given time zone.

The string must be a space-separated list of five elements, representing minutes, hours, month days, months and week days (in this order). Each element can be:

  • a number in the correct range for the given time unit: e.g. 3
  • a range: e.g. 2-5 which corresponds to 2,3,4,5
  • a range with a step: e.g. 1-6/3 which corresponds to 1,4
  • a wildcard: i.e. * which corresponds to all elements for the given time unit
  • a wildcard with a step: e.g. */4 which corresponds to one every four elements
  • a comma-separated list (without spaces) where each element is one of the previous ones: e.g. 8,2-4,1-5/2 which corresponds to 1,2,3,4,5,8

Months and week days can also be represented using the first three letters instead of numbers (e.g, mon, thu, may, oct…).

As an alternative, a shorthand representation can be used. The following options are available:

  • @yearly: at 0:00 on the first of January each year
  • @monthly: at 0:00 at the beginning of each month
  • @weekly: at 0:00 on Monday each week
  • @daily: at 0:00 each day
  • @hourly: each hour at 00

Trait Implementations§

Source§

impl<Z> Debug for CronSchedule<Z>
where Z: TimeZone + Debug,

Source§

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

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

impl<Z> Schedule for CronSchedule<Z>
where Z: TimeZone,

Source§

fn next_call_at(&self, _last_run_at: Option<SystemTime>) -> Option<SystemTime>

Compute when a task should be executed again. If this method returns None then the task should never run again and it is safe to remove it from the list of scheduled tasks.

Auto Trait Implementations§

§

impl<Z> Freeze for CronSchedule<Z>
where Z: Freeze,

§

impl<Z> RefUnwindSafe for CronSchedule<Z>
where Z: RefUnwindSafe,

§

impl<Z> Send for CronSchedule<Z>
where Z: Send,

§

impl<Z> Sync for CronSchedule<Z>
where Z: Sync,

§

impl<Z> Unpin for CronSchedule<Z>
where Z: Unpin,

§

impl<Z> UnwindSafe for CronSchedule<Z>
where Z: UnwindSafe,

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<'a, T, E> AsTaggedExplicit<'a, E> for T
where T: 'a,

Source§

fn explicit(self, class: Class, tag: u32) -> TaggedParser<'a, Explicit, Self, E>

Source§

impl<'a, T, E> AsTaggedImplicit<'a, E> for T
where T: 'a,

Source§

fn implicit( self, class: Class, constructed: bool, tag: u32, ) -> TaggedParser<'a, Implicit, Self, E>

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

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

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.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

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
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> ErasedDestructor for T
where T: 'static,