Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cancel node-schedule event after it has been set

Tags:

node.js

cron

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?

Thanks in advance for your help!

like image 278
ShahNewazKhan Avatar asked Oct 13 '15 21:10

ShahNewazKhan


1 Answers

In order to retrieve a specific job, you could create it with a unique name and you can retrieve it later via that unique name:

var j = schedule.scheduleJob(unique_name, date, function() {
});
// later on
var my_job = schedule.scheduledJobs[unique_name];
my_job.cancel();
like image 175
ShahNewazKhan Avatar answered Oct 21 '22 16:10

ShahNewazKhan