3 releases (breaking)

Uses old Rust 2015

0.4.17 May 17, 2022
0.3.17 Aug 13, 2020
0.2.17 Aug 13, 2020
0.2.15 Sep 12, 2017
0.1.12 Aug 25, 2017

#1381 in Rust patterns

Download history 165/week @ 2024-03-11 142/week @ 2024-03-18 104/week @ 2024-03-25 168/week @ 2024-04-01 148/week @ 2024-04-08 128/week @ 2024-04-15 151/week @ 2024-04-22 95/week @ 2024-04-29 193/week @ 2024-05-06 190/week @ 2024-05-13 141/week @ 2024-05-20 134/week @ 2024-05-27 116/week @ 2024-06-03 81/week @ 2024-06-10 153/week @ 2024-06-17 69/week @ 2024-06-24

446 downloads per month

Apache-2.0

9KB
120 lines

cronjob

A libary for creating cronjobs for your application methods.

It's on crates.io now, check it out https://crates.io/crates/cronjob.

How to use the project

Add this to your Cargo.toml under [dependencies]

cronjob = "0.4.17"

examples

This is an example for the unthreaded version.

extern crate cronjob;
use cronjob::CronJob;

fn main() {
    // Create the `CronJob` object.
    let mut cron = CronJob::new("Test Cron", on_cron);
    // Set to fire when seconds is 0, 2 or 4
    cron.seconds("0,2,4");
    // Set to fire when day of week is Monday or Friday
    cron.day_of_week("Mon,Fri");
    // Set offset for UTC
    cron.offset(0);
    // Start the cronjob
    cron.start_job();
}
    
// Our cronjob handler
fn on_cron(name: &str) {
    println!("{}: It's time!", name);
}

This is an example for the threaded version.

extern crate cronjob;
use cronjob::CronJob;

fn main() {
    // Create the `CronJob` object.
    let cron = CronJob::new("Test Cron", on_cron);
    // Set to fire when seconds is 0
    cron.seconds("0");
    // Set offset for UTC
    cron.offset(0);
    // Start the cronjob
    CronJob::start_job_threaded(cron)
}
    
// Our cronjob handler
fn on_cron(name: &str) {
    println!("{}: It's time!", name);
}

If you have any issues, please report.

Dependencies

~2–8.5MB
~49K SLoC