underway
underway

Reputation: 13

node-schedule undoing cancellation

I've been working with node for the first time in a while again and stumbled upon node-schedule, which for the most part has been a breeze, however, I've found resuming a scheduled task after canceling it via job.cancel() pretty difficult.

For the record, I'm using schedule to perform specific actions at a specific date (non-recurring) and under some circumstances cancel the task at a specific date but would later like to resume it.

I tried using job.cancel(true) after cancelling it via plain job.cancel() first as the documentation states that that would reschedule the task, but this has not worked for me. Using job.reschedule() after having cancelled job first yields the same result.

I could probably come up with an unelegant solution, but I thought I'd ask if anyone knows of an elegant one first.

Upvotes: 0

Views: 1383

Answers (1)

Sparw
Sparw

Reputation: 2743

It took me a while to understand node-schedule documentation ^^

To un-cancel a job, You have to give to reschedule some options.

If you don't pass anything to reschedule, this function returns false (Error occured)

For exemple, you can declare options, and pass this variable like this :

const schedule = require('node-schedule');

let options = {rule: '*/1 * * * * *'}; // Declare schedule rules

let job = schedule.scheduleJob(options, () => {
    console.log('Job processing !');
});

job.cancel(); // Cancel Job

job.reschedule(options); // Reschedule Job

Hope it helps.

Upvotes: 2

Related Questions