Node - the schedule is not working on time
I want to use node-schedule, I get information from the database every day and for each item I want to do something at a specific time. this is my code:
users.forEach(function(users_entry){
if(err){
console.log(err);
}
else{
var date = new Date(2014, 11, 29, 11, 45, 0);
schedule.scheduleJob(date,
function(){
console.log('The world is going to end today.');
});
}
});
but the above code does not run at the specified time and runs all the time. what is the problem?
+3
source to share
2 answers
i changed my code and used cron. https://www.npmjs.org/package/cron
it works really well :)
var CronJob = require('cron').CronJob;
new CronJob('* * * * * *', function(){
console.log('You will see this message every second');
}, null, true, "America/Los_Angeles");
+3
source to share
try it
var CronJob = require('cron').CronJob;
var job = new CronJob('00 00 12 * * 1-7', function() {
/*
* Runs every day
* at 12:00:00 AM.
*/
}, function () {
/* This function is executed when the job stops */
},
true, /* Start the job right now */
timeZone /* Time zone of this job. */
);
0
source to share