Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add functionality to limit missed runs. #13

Merged
merged 1 commit into from
Oct 23, 2019

Conversation

jordanmack
Copy link

@jordanmack jordanmack commented Oct 22, 2019

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);

@jordanmack jordanmack force-pushed the feature_limit_missed_runs branch from c72bd34 to 16b9545 Compare October 22, 2019 10:22
src/lib.rs Outdated
@@ -69,6 +69,7 @@ pub struct Job<'a> {
schedule: Schedule,
run: Box<(FnMut() -> ()) + 'a>,
last_tick: Option<DateTime<Utc>>,
limit_missed_runs: Option<usize>,
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi there!

I appreciate the pull request.

I feel like this new field would be better as just a usize instead of an option. It could default to 0. Not sure it being an option is buying us much here. :)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated.

@jordanmack jordanmack force-pushed the feature_limit_missed_runs branch from 16b9545 to 5ad3d7a Compare October 22, 2019 19:36
@lholden lholden merged commit bfe9a63 into lholden:master Oct 23, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants