Created
March 22, 2022 15:49
-
-
Save fmorency/127866581ae031c259c2463e76842b33 to your computer and use it in GitHub Desktop.
tokio-cron-scheduler shutdown handling/signal
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use tokio_cron_scheduler::{Job, JobScheduler}; | |
#[tokio::main] | |
async fn main() { | |
let mut sched = JobScheduler::new(); | |
let _ = sched.add( | |
Job::new_async("1/7 * * * * *", |_uuid, _l| { | |
Box::pin(async { | |
println!("I run async every 7 seconds"); | |
}) | |
}) | |
.unwrap(), | |
); | |
sched.shutdown_on_ctrl_c(); | |
let _ = sched.set_shutdown_handler(Box::new(|| { | |
Box::pin(async move { | |
println!("Shut down done"); | |
// std::process.exit(0); // This is needed for the application to shutdown | |
}) | |
})); | |
let _ = sched.start().await; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment