#cron #crontab #scheduler #job #tokio

tokio-cron-scheduler

Schedule tasks on tokio using cron-like annotation

5 releases

0.2.1 Mar 25, 2021
0.2.0 Mar 25, 2021
0.1.4 Mar 25, 2021

#61 in Date and time

Download history 46/week @ 2021-03-04 36/week @ 2021-03-11 18/week @ 2021-03-18 114/week @ 2021-03-25 156/week @ 2021-04-01 280/week @ 2021-04-08 447/week @ 2021-04-15 19/week @ 2021-04-22 36/week @ 2021-04-29 14/week @ 2021-05-06 41/week @ 2021-05-13 56/week @ 2021-05-20 102/week @ 2021-05-27 91/week @ 2021-06-03 95/week @ 2021-06-10

394 downloads per month

MIT/Apache

25KB
509 lines

tokio-cron-scheduler

Use cron-like scheduling in an async tokio environment.

Inspired by https://github.com/lholden/job_scheduler

Usage

Please see the Documentation for more details.

Be sure to add the job_scheduler crate to your Cargo.toml:

[dependencies]
tokio-cron-scheduler = "*"

Creating a schedule for a job is done using the FromStr impl for the Schedule type of the cron library.

The scheduling format is as follows:

sec   min   hour   day of month   month   day of week   year
*     *     *      *              *       *             *

Time is specified for UTC and not your local timezone. Note that the year may be omitted.

Comma separated values such as 5,8,10 represent more than one time value. So for example, a schedule of 0 2,14,26 * * * * would execute on the 2nd, 14th, and 26th minute of every hour.

Ranges can be specified with a dash. A schedule of 0 0 * 5-10 * * would execute once per hour but only on day 5 through 10 of the month.

Day of the week can be specified as an abbreviation or the full name. A schedule of 0 0 6 * * Sun,Sat would execute at 6am on Sunday and Saturday.

A simple usage example:

use tokio_cron_scheduler::{JobScheduler, JobToRun, Job};

#[tokio::main]
async fn main() {
    let mut sched = JobScheduler::new();

    sched.add(Job::new("1/10 * * * * *", |uuid, l| {
        println!("I run every 10 seconds");
    }).unwrap());

    sched.add(Job::new("1/30 * * * * *", |uuid, l| {
        println!("I run every 30 seconds");
    }).unwrap());

    sched.start().await;
}

Similar Libraries

  • job_scheduler The crate that inspired this one
  • cron the cron expression parser we use.
  • schedule-rs is a similar rust library that implements it's own cron expression parser.

License

TokioCronScheduler is licensed under either of

Contributing

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

Please see the CONTRIBUTING file for more information.

Dependencies

~4.5MB
~70K SLoC