This is the code to execute a Cronjob each 20 seconds.
let mut cron = CronJob::new("EXPIRING_VOUCHERS", handle_expiring_vouchers);
// Start the cronjob
But how would I make a cronjob which executes each last day of the month?
How would I do that in the CronJob crate? They only have functions like
I would just use the
cron crate (on which
cronjob depends) and spawn a thread myself.
If you have a look at the code of
cronjob it's a really thin (and imo bad) wrapper for
cronjob won't report an error and will panic if your schedule is invalid, the thread it spawns will also get zombified.
Okay, so I'll take the first day of each month instead and then just subtract one month.
I currently have this
let expression = "0 0 1 * *";
let schedule = Schedule::from_str(expression).unwrap();
The documentation of the cron-crate only explains on how to output the next launching times. But how do I just trigger a function with this cron?
[Very] Naively, take the next upcoming job. Subtract from it the current time, that gets you a duration, wait for that duration, run your code.