设置节点计划事件后将其取消 [英] Cancel node-schedule event after it has been set
本文介绍了设置节点计划事件后将其取消的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我计划使用 node-schedule 为约会提醒设置推送通知,如下所示:
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
});
现在,我知道您可以通过调用cancel()取消事件:
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?
请提前感谢您
推荐答案
要检索特定作业,可以使用唯一名称创建该作业,以后可以通过以下方式进行检索唯一的名称:
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();
这篇关于设置节点计划事件后将其取消的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文