Scheduler for node that has been running for> 25 days.

I need a task scheduler for a web application made in node. I've looked at node-cron and node-scheduler, but the stand seems to be built on top of the Node setTimeout()

. The problem is that it setTimeout()

has a maximum timeout of about 25 days as stated here: http://nodejs.org/api/globals.html#globals_settimeout_cb_ms

If I need planning, say every third month ... how can I solve that?

+3


source to share


2 answers


Have a look at this line at node-cron

: https://github.com/ncb000gt/node-cron/blob/master/lib/cron.js#L382

This basically means that node-cron is handling the overflow setTimeout()

and splitting a larger time interval into several smaller ones. You should be able to use it safely.



In fact, this functionality also extends to node-cron unit tags . If the value specified in setTimeout()

is greater than the maximum value, it fires immediately. This module checks if after a huge value (1000 months) has been fed, the test will fail in a 250ms time window.

'test long wait should not fire immediately': function(assert) {
    assert.expect(1);
    var count = 0;
    var d = new Date().getTime() + 31 * 86400 * 1000;
    var job = cron.job(new Date(d), function() {
      assert.ok(false);
    });
    job.start();
    setTimeout(function() {
      job.stop();
      assert.ok(true);
      assert.done();
    }, 250);
},

      

+2


source


agenda will also suit your needs. It stores the time of the schedule job in the database and will then poll the database at a specified interval ( agenda.processEvery

), which looks for jobs to be completed.



Full disclosure, I am the author of the agenda.

+1


source







All Articles