Crate skedge[][src]

Expand description

skedge

skedge is a single-process job scheduler. To use the optional CFFI, enable the “ffi” feature.

Define a work function:

fn job() {
    println!("Hello, it's {}!", chrono::Local::now().to_rfc2822());
}

You can use up to six arguments:

fn greet(name: &str) {
    println!("Hello, {}!", name);
}

Instantiate a Scheduler and schedule jobs:

let mut schedule = Scheduler::new();

every(10).seconds()?.run(&mut schedule, job)?;
every(10).minutes()?.run(&mut schedule, job)?;
every_single().hour()?.run(&mut schedule, job)?;
every_single().day()?.at("10:30")?.run(&mut schedule, job)?;
every(5).to(10)?.minutes()?.run(&mut schedule, job)?;
every_single().monday()?.run(&mut schedule, job)?;
every_single().wednesday()?.at("13:15")?.run(&mut schedule, job)?;
every_single().minute()?.at(":17")?.run(&mut schedule, job)?;
every(2)
    .to(8)?
    .seconds()?
    .until(Local::now() + chrono::Duration::seconds(30))?
    .run_one_arg(&mut schedule, greet, "Good-Looking")?;

Note that you must use the appropriate run_x_args() method for job functions taking multiple arguments. In your main loop, you can use Scheduler::run_pending() to fire all scheduled jobs at the proper time:

loop {
    if let Err(e) = schedule.run_pending() {
        eprintln!("Error: {}", e);
    }
    std::thread::sleep(std::time::Duration::from_secs(1));
}

Structs

A Job is anything that can be scheduled to run periodically.

A Scheduler creates jobs, tracks recorded jobs, and executes jobs.

Enums

Functions

Convenience function wrapping the Job constructor.

Convenience function wrapping the Job constructor with a default of 1.

Type Definitions

Each interval value is an unsigned 32-bit integer

A Tag is used to categorize a job.