1

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...

Lalit Kolate
  • 31
  • 1
  • 4

2 Answers2

0

if node-cron is not the only prefrence for you then you can use https://github.com/agenda/agenda

  • While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. – Viktor Ivliiev Mar 15 '22 at 10:16
  • mm agenda also needs an external storage though.. isn't there anything that's self contained? – PptSbzzgt Sep 22 '22 at 06:28
0

There's no need to require the same package twice, so you should remove Cron2 on the second line. Thus the line var TaskTwo = Cron2.schedule('*/11 * * * *', async() => { should be changed to:

var TaskTwo = Cron.schedule('*/11 * * * *', async() => {

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:

TaskOne.start();

TaskTwo.start();
Tyler2P
  • 2,324
  • 26
  • 22
  • 31
Danz Tim
  • 180
  • 1
  • 3
  • 10