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

Can there has an api to get a job next_run_time? #32

Closed
Hellager opened this issue Sep 4, 2022 · 3 comments
Closed

Can there has an api to get a job next_run_time? #32

Hellager opened this issue Sep 4, 2022 · 3 comments

Comments

@Hellager
Copy link

Hellager commented Sep 4, 2022

Thanks for your greet job, this crate works very well.
I did found that there's a function time_till_next_job but it's not specified for a job,
can there has an api to get a specific job's next_run_time like this get_next_run_time?

@Hellager
Copy link
Author

Hellager commented Sep 5, 2022

For now, it's ok to do it like this

// after the JobScheduler start
use cron::{Schedule as Cron_Schedule};
use chrono::{Utc, DateTime};
use std::str::FromStr;

.....
let cron_expression = "1/10 * * * * *";
sched.add(Job::new("1/10 * * * * *", |uuid, l| {
    let cron_schedule = Cron_Schedule::from_str(&cron_expression).unwrap();
    let next_run_time_vec: Vec<DateTime<Utc>> = cron_schedule.upcoming(Utc).take(1)
                  .filter_map(|datetime| Some(datetime)).collect::<Vec<DateTime<Utc>>>();
    println!("cron job next run time: {}", next_run_time_vec[0].to_string());
 }).await.unwrap());

@mvniekerk
Copy link
Owner

Hi @Hellager
Thanks for the post - I'll check into this

@mvniekerk
Copy link
Owner

So @Hellager
Have a look
https://github.com/mvniekerk/tokio-cron-scheduler/releases/tag/v0.8.1

Implemented.

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

No branches or pull requests

2 participants