-
Notifications
You must be signed in to change notification settings - Fork 249
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
Exception thrown inside scheduled task is silently swallowed #399
Comments
Meanwhile, croner has an option to control this - ( |
I've also been running into this issue, I've spent a lot of time debugging one of my scheduled tasks that seemingly stopped in the middle of executing - turns out it was throwing an exception and just stopping. |
I did a workaround for async tasks by using a wrapper function: function scheduleAsyncCron(expression, fn, options) {
cron.schedule(expression, () => fn().catch((e) => console.error(e)), options);
}
scheduleAsyncCron('* * * * *', async () => {
await asyncFunctionToRun();
}); |
If the function or closure passed as a parameter of the
cron.schedule
happens to throw an exception anywhere, and is not properly catched withing the body of the function, the library swallows the exception silently with no indication as to whether an exception has happened. This makes debugging more difficult.The library should catch and dump the unhandled exception. Failing that, this caveat should be documented in the manual so the programmer can guard against it from the very start.
The text was updated successfully, but these errors were encountered: