Skip to content

Instantly share code, notes, and snippets.

@fmorency
Created March 22, 2022 15:49
Show Gist options
  • Save fmorency/127866581ae031c259c2463e76842b33 to your computer and use it in GitHub Desktop.
Save fmorency/127866581ae031c259c2463e76842b33 to your computer and use it in GitHub Desktop.
tokio-cron-scheduler shutdown handling/signal
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