如何使用nodejs中的node-cron在不同的时间执行多个cron作业?
我怎样才能在不同的时间执行这个?请帮忙解决这个问题。预先感谢...
const Cron = require('node-cron');
const Cron2 = require('node-cron');
var TaskOne = Cron.schedule('*/10 * * * *', async() => {
//first job implemented here and its working fine
function1();
});
var TaskTwo = Cron2.schedule('*/11 * * * *', async() => {
// Second job implemented here....
//Why this block is not getting executed???????????????????????
function2();
});
我怎样才能在不同的时间执行这个? TaskTwo 没有被执行。调试器不会进入 TaskTwo。请帮忙解决这个问题。提前致谢...
How can I execute this with different timings? Please help on this. Thanks in Advance...
const Cron = require('node-cron');
const Cron2 = require('node-cron');
var TaskOne = Cron.schedule('*/10 * * * *', async() => {
//first job implemented here and its working fine
function1();
});
var TaskTwo = Cron2.schedule('*/11 * * * *', async() => {
// Second job implemented here....
//Why this block is not getting executed???????????????????????
function2();
});
How can I execute this with different timings? TaskTwo is not getting executed. Debugger not goes into TaskTwo. Please help on this. Thanks in Advance...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果
node-cron
不是您唯一的偏好,那么您可以使用 https:// github.com/agenda/agendaif
node-cron
is not the only prefrence for you then you can use https://github.com/agenda/agenda不需要两次
require
相同的包,因此您应该删除第二行的Cron2
。因此,var TaskTwo = Cron2.schedule('*/11 * * * *', async() => {
行应更改为:至于为什么第二个计划不起作用,它可能是因为您没有
start()
计划,如 https://github.com/node-cron/node-cron#start。因此,在脚本末尾添加以下代码可能会触发两个 cron 运行:There's no need to
require
the same package twice, so you should removeCron2
on the second line. Thus the linevar TaskTwo = Cron2.schedule('*/11 * * * *', async() => {
should be changed to:As for why the second schedule is not working, it might be because you didn't
start()
the schedule, as shown in https://github.com/node-cron/node-cron#start. So adding the code below at the end of your script might trigger both cron to run: