node-cron
node-cron copied to clipboard
Cron jobs stop working (Can an error inside the time function result in job stopping?)
Description
Guys for some time now, about 3 weeks we have been experiencing cron job stopping. We can't identify and there is talks to move away from this library.
I'm sure this is an easy thing, this library has been the most robust one ever.
I coded our scheduler with it and it served us for 6 years. I'm not in the issue right now, but I want to collaborate.
We have a package declaration of 1.6.0 ("cron": "^1.6.0",).
We user an every minute one that stops calling our notifications processing. (or so we think).
Almost all or our jobs are the same (they just change in the rest resource being called)
function schedule() {
cronJob = cron.job("0 */1 * * * *", async function() {
log.info('Scheduled Job ' + name + ' called');
const api_resource = process.env.API_BASE_URL + 'v3/notifications/process';
const now = new Date();
const opts = {
headers: {'Authorization': 'TOKEN'}
};
try {
await axios.post(api_resource, {}, opts);
log.info('Scheduled Job ' + name + ' triggered successfully.');
} catch (error) {
log.error('Scheduled Job ' + name + ' was not posted. Error was', error);
}
});
cronJob.start();
}
We dir list all jobs, and for each we call the function schedule.
I understand the lack of items but any pointers, any ideas would be appreciated it. Thank you so much.
The bottom line is that every so often we need to redeploy our api to restart our scheduler.
Screenshots
No response
Additional information
No response
Try https://github.com/hexagon/croner, it has about the same interface, built to be solid, and is actively developed.
@franky-continu Try "1 */1 * * * *". Zero second randomly seems problematic.
@Hexagon Thanks for the suggestion. I will give a try.
Another thing to try (even though it might be a long shot) is to omit /1 from minutes.
*/1 is pretty much the same expression as * , however the first option will probably trigger code that could cause extra problems.
@franky-continu Try "1 */1 * * * *". Zero second randomly seems problematic.
@Hexagon Thanks for the suggestion. I will give a try.
Thank you so much for the responses.
Sorry, what is the difference between Zero and 1 in terms of randomly. I'm setting to call notifications on the 0 second of every minute. Perhaps put *. but We usually set it on the dot (as in zero 0).
I'm not sure I follow the it being random thing.
Another thing to try (even though it might be a long shot) is to omit
/1from minutes.
*/1is pretty much the same expression as*, however the first option will probably trigger code that could cause extra problems.
I took it from the examples. I believe if I follow what you mentioned instead of "0 */1 * * * *" I would have "0 * * * * *" or "1 * * * * *" (if you were including @albertosantini 's response)
wouldn't that tick every second?
@franky-continu "1 */1 * * * *" means on the first second of every minute. Try that.
If you search "zero" in the issues you see a few corner cases about zero in seconds. I have been experimenting, with zero seconds, sometimes the call is not triggered, need to restart the app.
excellent thank you so much