10 stable releases

Uses old Rust 2015

1.2.1 Apr 1, 2020
1.1.0 Oct 26, 2019
1.0.6 Nov 7, 2018
1.0.5 Aug 24, 2018
1.0.2 Mar 4, 2017

#213 in Date and time

Download history 192/week @ 2024-07-21 182/week @ 2024-07-28 182/week @ 2024-08-04 281/week @ 2024-08-11 182/week @ 2024-08-18 219/week @ 2024-08-25 237/week @ 2024-09-01 164/week @ 2024-09-08 179/week @ 2024-09-15 253/week @ 2024-09-22 287/week @ 2024-09-29 103/week @ 2024-10-06 157/week @ 2024-10-13 138/week @ 2024-10-20 218/week @ 2024-10-27 213/week @ 2024-11-03

731 downloads per month
Used in 8 crates

MIT/Apache

12KB
109 lines

JobScheduler

A simple cron-like job scheduling library for Rust.

Usage

Please see the Documentation for more details.

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

[dependencies]
job_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:

extern crate job_scheduler;
use job_scheduler::{JobScheduler, Job};
use std::time::Duration;

fn main() {
    let mut sched = JobScheduler::new();

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

    loop {
        sched.tick();

        std::thread::sleep(Duration::from_millis(500));
    }
}

Similar Libraries

  • cron the cron expression parser we use.
  • schedule-rs is a similar rust library that implements it's own cron expression parser.

License

JobScheduler 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

~5–10MB
~109K SLoC