Reputation: 529
I'm using node-cron to use cron.
Here is what I have done so far -
cron.schedule('10 * * * *', cronJobController.sendReminderNotification, { scheduled: true, timezone: 'Asia/Kolkata' });
cron.schedule('20 * * * *', cronJobController.sendReminderNotification, { scheduled: true, timezone: 'Asia/Kolkata' });
cron.schedule('30 * * * *', cronJobController.sendReminderNotification, { scheduled: true, timezone: 'Asia/Kolkata' });
I have to write a separate statement for every specific minute.
How can I achieve this in a single line of code?
Any help would be appreciated.
Thanks in advance.
Upvotes: 2
Views: 4851
Reputation: 5051
You can use '*/10 * * * *'
So Just try
cron.schedule('*/10 * * * *', cronJobController.sendReminderNotification, { scheduled: true, timezone: 'Asia/Kolkata' });
Upvotes: 2
Reputation: 108651
You can use the scheduling expression '0/10 * * * *'
to get a run every ten minutes.
But think about whether you want to run your job at the precise top of the hour. There's tonnage of code out there on the net that runs at the top of the hour. If you are using any sort of network service from your code you may want to run at '1/10 * * * *'
to avoid top-of-the-hour congestion.
Or better yet, have your code delay a random time between 0 and 10 seconds before doing its thing.
Upvotes: 1
Reputation: 30685
This code should do what you wish, we can't run at minute 60, but we can run at minute 0 which should give you the same result:
cron.schedule('0,10,20,30,40,50 * * * *', cronJobController.sendReminderNotification, { scheduled: true, timezone: 'Asia/Kolkata' });
Upvotes: 1