Issue
I am trying to do a cron job but it only works if the time specified is every second or every minute. However, If I try to specify a time (day, month , hour and minute) I am unable to get a response.
CronService.js file :
var CronJob = require('cron').CronJob;
module.exports = {
startJob : function(time) {
new CronJob(time, function() {
console.log('test');
}, null, true,'Asia/Singapore');
}
}
some controller.js file :
startCronService : function(req, res, next) {
var time = '12 15 29 8 *';
CronService.startJob(time);
},
I tried changing the timezones to 'America/New_York' and adjust my time as well. but the cron job will never respond.
Am I doing something wrong with the time syntax?
Solution
After trying multiple things, I found out that you must provide the name of the month rather than the number (Jan,Feb) etc. Although, the npm documentation mentioned that we are able to use both, but that is false unfortunately.
Answered By - Hussein Menshawi