admin管理员组文章数量:1388748
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 * * *
本文标签: javascriptrunSchedule job every hour in nodeJSStack Overflow
版权声明:本文标题:javascript - runSchedule job every hour in nodeJS - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744599648a2614992.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论