Khai Dao
Khai Dao

Reputation: 55

How to start schedule at reboot only on node-cron?

I would start my schedule whenever my server starts, On cronjob I use @reboot to schedule it, but seems this feature doesn't work on node-cron.

cron.schedule('@reboot', () => {
    console.log('will execute at reboot');
   
});

Upvotes: 1

Views: 500

Answers (1)

Paulo Berezini
Paulo Berezini

Reputation: 200

I have the same issue, it's impossible to do with "node-cron" lib. But you can resolve it, by another ways. When u start schedule job in the first time:

  • Write current date to DB
  • Write current date to local file

And you need some controller for checking "if task already done".

var cron = require('node-cron');
var task = cron.schedule('* * * * *', () =>  {
  //check if current date != date from DB/local file => start the job
});

enter image description here

Upvotes: 1

Related Questions