i'm working with nodejs and Mongodb. i want to run job every user define hours using npm node-schedule but its did't work.
Here is my code
var schedule = require('node-schedule');
var mailTimer = 1;
var intMail = schedule.scheduleJob('* * '+mailTimer+' * *', function(){
console.log('its run');
});
//its means its run every 1 hour.
i'm working with nodejs and Mongodb. i want to run job every user define hours using npm node-schedule but its did't work.
Here is my code
var schedule = require('node-schedule');
var mailTimer = 1;
var intMail = schedule.scheduleJob('* * '+mailTimer+' * *', function(){
console.log('its run');
});
//its means its run every 1 hour.
Share
Improve this question
edited Apr 5, 2016 at 10:46
Parthapratim Neog
4,4787 gold badges46 silver badges81 bronze badges
asked Apr 5, 2016 at 9:56
Kaushik MakwanaKaushik Makwana
2,57610 gold badges37 silver badges55 bronze badges
6
- What is the response that you get? – Parthapratim Neog Commented Apr 5, 2016 at 10:08
- nothing get any response. – Kaushik Makwana Commented Apr 5, 2016 at 10:09
-
There needs to be one more
*
at the end of the input string if I'm not wrong. Add it and check the response. – Parthapratim Neog Commented Apr 5, 2016 at 10:09 - yes..you are right but how can i run every hours? i need to like * * /1 * * * * or not? – Kaushik Makwana Commented Apr 5, 2016 at 10:13
-
* * 1 * * *
should do it. Try! – Parthapratim Neog Commented Apr 5, 2016 at 10:15
3 Answers
Reset to default 6Try this :
var schedule = require('node-schedule');
var rule = new schedule.RecurrenceRule();
rule.hour = 1;
var intMail = schedule.scheduleJob(rule, function(){
console.log('its run');
});
You can use other rules to set like :
* * * * * *
┬ ┬ ┬ ┬ ┬ ┬
│ │ │ │ │ |
│ │ │ │ │ └ day of week (0 - 7) (0 or 7 is Sun)
│ │ │ │ └───── month (1 - 12)
│ │ │ └────────── day of month (1 - 31)
│ │ └─────────────── hour (0 - 23)
│ └──────────────────── minute (0 - 59)
└───────────────────────── second (0 - 59, OPTIONAL)
Here's another example using other rules:
var j = schedule.scheduleJob({hour: 14, minute: 30, dayOfWeek: 0}, function(){
console.log('Time for tea!');
});
More examples can be found here
The crontab config should be 0 */'+mailTimer+' * * *
.
There needs to be one more *
at the end of the input string if I'm not wrong. Add it and check the response. For one hour you can use * * 1 * * *