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>
impl CronSchedule<Utc>
Sourcepub fn new(
minutes: Vec<u32>,
hours: Vec<u32>,
month_days: Vec<u32>,
months: Vec<u32>,
week_days: Vec<u32>,
) -> Result<Self, ScheduleError>
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.
Sourcepub fn from_string(schedule: &str) -> Result<Self, ScheduleError>
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,
impl<Z> CronSchedule<Z>where
Z: TimeZone,
Sourcepub 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>
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.
Sourcepub fn from_string_with_time_zone(
schedule: &str,
time_zone: Z,
) -> Result<Self, ScheduleError>
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>
impl<Z> Debug for CronSchedule<Z>
Source§impl<Z> Schedule for CronSchedule<Z>where
Z: TimeZone,
impl<Z> Schedule for CronSchedule<Z>where
Z: TimeZone,
Source§fn next_call_at(&self, _last_run_at: Option<SystemTime>) -> Option<SystemTime>
fn next_call_at(&self, _last_run_at: Option<SystemTime>) -> Option<SystemTime>
None
then the task should
never run again and it is safe to remove it from the
list of scheduled tasks.