Crate skedge

Source
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 {}!", jiff::Zoned::now());
}

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(Zoned::now().checked_add(30.seconds())?)?
    .run_one_arg(&mut schedule, greet, "Cool Person")?;

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§

Job
A Job is anything that can be scheduled to run periodically.
Scheduler
A Scheduler creates jobs, tracks recorded jobs, and executes jobs.

Enums§

Error

Functions§

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

Type Aliases§

Interval
Each interval value is an unsigned 32-bit integer
Result
Tag
A Tag is used to categorize a job.