[][src]Crate crony

Crony: a simple cron runner

Use the Job trait to create your cron job struct, pass it to the Runner and then start it via run() method. Runner will spawn new thread where it will start looping through the jobs and will run their handle method once the scheduled time is reached.

If your OS has enough threads to spare each job will get its own thread to execute, if not it will be executed in the same thread as the loop but will hold the loop until the job is finished.

Please look at the Job trait documentation for more information.

Example

extern crate crony;

use crony::{Job, Runner, Schedule};
use std::str::FromStr;

struct ExampleJob;
impl Job for ExampleJob {
    fn schedule(&self) -> Schedule {
        // Runs every minute
        Schedule::from_str("0 * * * * *").unwrap()
    }
    fn handle(&self) {
        println!("Hello, I am cron job running at: {}", self.now());
    }
}

fn main() {
    println!("Hello world");
    Runner::new().add(Box::new(ExampleJob)).run();
}

/*
Hello world
Hello, I am cron job running at: 2020-12-10 16:01:59.740944 UTC
Hello, I am cron job running at: 2020-12-10 16:02:59.821043 UTC
*/

Structs

Runner

Runner that will hold all the jobs and will start up the execution and eventually will stop it.

Schedule

Re-export of (cron)[https://crates.io/crates/cron] crate struct for setting the cron schedule time. Read its documentation for more information and options.

TRACKER

Singleton instance of a tracker that won't allow same job to run again while its already running unless you specificly allow the job to run in parallel with itself

Tracker

Struct for marking jobs running

Traits

Job