我打算使用node-schedule为约会提醒设置推送通知,如下所示:
int main(int argc, const char **argv[])
{
for(int i = 0; i < argc; i++) {
std::cout << argv[i] << std::endl;
}
return 0;
}
现在我知道您可以通过调用cancel()来取消活动:
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
});
但是,如果客户端的用户决定将约会更改为其他日期,如何才能取消该特定作业?
提前感谢您的帮助!
答案 0 :(得分:22)
为了检索特定作业,您可以使用唯一名称创建它,稍后可以通过该唯一名称检索它:
var j = schedule.scheduleJob(unique_name, date, function() {
});
// later on
var my_job = schedule.scheduledJobs[unique_name];
my_job.cancel();
答案 1 :(得分:0)
var randf = require('randomstring');
var jobId = randf.generate(10); //randomsrting
var at = new Date();
var time = at.setSeconds(at.getSeconds() + Number(5)) //after 5 second
schedule.scheduleJob(jobId, new Date(time),function(){
schedule.cancelJob(jobId);
console.log('hi--viral');
});