question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Cancel node-schedule event after it has been set

See original GitHub issue

I am planning on using node-schedule to set up push notifications for appointment reminders as follows:

var schedule = require('node-schedule');
var date = req.body.date;   // Date for reminder from client request 
var j = schedule.scheduleJob(date, function(){
    // Send push notification
});

Now I know you can cancel the event by calling cancel():

j.cancel()

However, how can I refer to that specific job to cancel if the user from the client side decides to change the appointment to a different date later on?

For example user wants to set a reminder for December 25th 2015, then a few days later they decide to change the reminder to December 24th, 2015.

How can I reference the event that was scheduled for December 25th, 2015 and cancel it and create a new one for December 24th, 2015.

Thanks in advance for your help!

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:11 (7 by maintainers)

github_iconTop GitHub Comments

2reactions
santigimenocommented, Oct 24, 2015

@ShahNewazKhan I’m not sure I understand correctly what the problem is:

  • You have problems getting a reference to a job by the scheduled date, or
  • You need to be able to re-schedule a specific job.

In case your problem is the first one, I don’t think there’s a way to do that: you could have multiple job scheduled for the same time. In order to retrieve a specific job, you could always create it with a unique name and you could always retrieve it later via that unique name:

var j = schedule.scheduleJob(unique_name, date, function() {
});
// later on
var my_job = schedule.scheduledJobs[unique_name];

In case you want to be able to reschedule the job, there’s no specific method, but you can do:

var j = schedule.scheduleJob(date, function(){
    // Send push notification
});

// later on
var job_method = j.job;
j.cancel();
var new_job = schedule.scheduleJob(date, job_method);
Read more comments on GitHub >

github_iconTop Results From Across the Web

Cancel node-schedule event after it has been set
@ShahNewazKhan it seems it doesn't work with node-schedule version 1.3.2. if there is a unique_name parameter, function is not called at specified date...
Read more >
Cancel node-schedule event after it has been set-node.js
Coding example for the question Cancel node-schedule event after it has been set-node.js.
Read more >
node-schedule - npm
Node Schedule is a flexible cron-like and not-cron-like job ... A canceled event when an invocation is canceled before it's executed.
Read more >
How to use the node-schedule.cancelJob function in ... - Snyk
To help you get started, we've selected a few node-schedule.cancelJob examples, based on popular ways it is used in public projects.
Read more >
Scheduling Jobs with Node.js - Reflectoring
For example, if the asterisk symbol is in the “month” field, it means the task is run every month. , : The comma...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found