Open ks-s-a opened 5 years ago
This is important.
If an error is thrown by a async function inside the cronjob callback.. then even with a try.. catch I will get
(node:8637) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
Currently there isn't a way. But, I do see value in this. If I get some time I'll implement this, otherwise I'd happily review a PR for this.
Thanks for bringing it up.
Any updates on this?
any update on this?
This would be VERY handy.... +1
The palliative solution I found was to retrieve the CronJob callback list (job._callbacks
) and for each spawn
object (child_process) within it, add an handler to the spawn 'error'
event, so I can at least be notified that something has gone wrong in the child_process ...
var job = new CronJob(/* parameters for the constructor */);
/* In practice you will only have one spawn to execute at each tick */
job._callbacks.forEach((spawn) => {
spawn.on('error', (err) => {
console.error('Failed to start subprocess.');
});
});
You can do the same gambling on job.onComplete
, as it turns into a spawn after all.
I am not proud to share this tip, but as long as there is no other solution, it goes anyway.
What is the status of this feature? I noticed throwing an exception from the callback function given to cron.schedule will not terminate the overall process, but it just keeps executing. Does the node cron module apply a try catch under the hood or how can this behavior be explained?
this feature's scope seems simple and well-defined enough:
CronJob
to provide an error-handling functionHi @sheerlox @ncb000gt, I would like to add this feature.
related issue:
Hello.
Is there a way to catch an error during the cronjob execution? As I see cron.start() doesn't return promise, so we can't just hang a .catch() there.
I guess it's common need so some people found a good approach to solve it.
Thank you a lot!
Feature specification: https://github.com/kelektiv/node-cron/issues/426#issuecomment-1741837777