【问题标题】:send push message using schedule job to clients使用计划作业向客户端发送推送消息
【发布时间】:2015-10-26 08:49:35
【问题描述】:

现在我正在使用 node.js 和 GCM 开发第三方服务器。 我的应用故事是第一个客户选择时间。 这次我的服务器推送消息。 我尝试使用 node-schedule 但是 我找不到如何取消特定的时间表。 如何处理计划作业。 例如5 客户选择下午 5 点推送消息。 但是一位客户想要更改时间,另一位客户想要取消推送消息。 如何使用计划作业更改时间和取消特定客户的时间。

【问题讨论】:

  • 我也有同样的问题,发现定时任务存储在var schedule = require('node-schedule'); var scheduledtasks = schedule.scheduledJobs;,但是不知道怎么利用

标签: node.js cron google-cloud-messaging scheduled-tasks


【解决方案1】:

您需要为计划任务命名。

首先这里是你如何使用 node-schedule 来安排任务

var schedule = require('node-schedule');
var date = new Date();
date.setMinutes(date.getMinutes() + 2);
schedule.scheduleJob('hereisthename', date, function(params)
{

  //Tasks to execute

}.bind(null, params));

它将安排一个将在两分钟内执行的任务,名称为“hereisthename”

如果你想取消它

var scheduled = schedule.scheduledJobs;
if (scheduled['hereisthename'] != null)
   scheduled['hereisthename'].cancel();

【讨论】:

  • 如果节点服务器被重置。 (关闭再打开)...它会取消之前的所有时间表吗?
  • 不,我检查了这个,一旦节点服务器被重置,所有预定的作业都消失了。
猜你喜欢
  • 2015-01-12
  • 2023-04-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-04-07
  • 2019-04-29
  • 1970-01-01
相关资源
最近更新 更多