lholden / job_scheduler

A simple cron-like job scheduling library for Rust.
Apache License 2.0
196 stars 34 forks source link

Add functionality to limit missed runs. #13

Closed jordanmack closed 4 years ago

jordanmack commented 4 years ago

Add functionality to limit missed runs. This should take care of #12. It also helps with #8, but it's not a full solution since it still "queues" a single missed run that executes immediately on the next tick.

The default is a single missed run because this is a safe value. Equivalent example:

let mut job = Job::new("0/1 * * * * *".parse().unwrap(), || {
    println!("I get executed every 1 seconds!");
});
job.limit_missed_runs(1);

The original unlimited functionality can easily be turned back on.

let mut job = Job::new("0/1 * * * * *".parse().unwrap(), || {
    println!("I get executed every 1 seconds!");
});
job.limit_missed_runs(0);

You can also set a custom limit.

let mut job = Job::new("0/1 * * * * *".parse().unwrap(), || {
    println!("I get executed every 1 seconds!");
});
job.limit_missed_runs(99);