0

I want a task to be executed every month on a specific date as soon as it hits the end point /shcheduleTaskEveryMonth. Suppose 17th of every month at 4:29pm evening I want to run a job/task.

And this is the code I am trying to achieve this: Just wanted to be sure if I am doing right please!

PS. This end point gets called once user account is created.

 router.get('/shcheduleTaskEveryMonth', function (req, res) {

    var schedule = require('node-schedule');
    var dateFormated = new Date(Fri Jan 17 2021 16:29:12 GMT+0530 (India Standard Time));
    
          var j = schedule.scheduleJob(dateFormated.getMinutes() +' '+dateFormated.getHours()+' '+dateFormated.getDate() + ' * *', function(){
              console.log('Your scheduled job every month');
          });
    });

How can I achieve that?

UPDATE: I just want to fit the above code simple wise similar to this:

var j = schedule.scheduleJob('42 * * * *', function(){
  console.log('The answer to life, the universe, and everything!');
});

Since it's a simple and understandable code I am unable to extract and the add the code likewise. Thanks!

Biku7
  • 450
  • 6
  • 16
  • 1
    You can make use of https://crontab.guru to check the timing of your job is correct. – thatguy Jan 15 '21 at 08:09
  • ya i got that. But my timing units are variables as well not contants like this: scheduleJob(dateFormated.getMinutes() +' '+dateFormated.getHours()+' '+dateFormated.getDate() + ' * *' So want to know if it will work like this or not? – Biku7 Jan 15 '21 at 08:14

0 Answers0