1

我有一个使用 Heroku 部署的解析服务器(来自我的 GitHub 存储库)并由 mongoLab 托管。我正在尝试在我的应用程序中发送预定的推送通知,而 kue 似乎是最可行的选择。但是,由于我对它非常陌生,我不确定如何接近它。我相信我已经在我的服务器上正确安装了 kue(通过 GitHub)。现在,我想安排这段代码在未来的某个日期执行:

    Parse.Cloud.define("sendPush", function(request, response) {


      var pushQuery = new Parse.Query(Parse.Installation);
      pushQuery.equalTo('username', request.params.targetUsername);

      Parse.Push.send({
        where: pushQuery, // Set our Installation query                                                                                                                                                              
        data: {
          alert: 'Hello!',
          badge: 'Increment',
          sound: 'PopDing.caf'
        },   
      }, { success: function() {
  console.log("#### PUSH OK");
      }, error: function(error) {
  console.log("#### PUSH ERROR" + error.message);
      }, useMasterKey: true});

    });

如果我以正确的方式处理这个问题,那么我需要代码来简单地安排一个作业(上面的代码)在未来的指定时间执行。我没有将代码安排为定期或间隔运行,只是在将来的指定时间运行一次。非常感谢您的回答或任何建议,谢谢!

4

1 回答 1

1

这是一个示例,您如何 在未来的特定时间仅使用kue完成一次调度此任务:(12 小时后)

var kue = require( 'kue' );

// create our job queue
var jobs = kue.createQueue();

// one minute
var minute = 60000;

var job= jobs.create( 'parseCloud', {
    alert: 'Hello!',
          badge: 'Increment',
          sound: 'PopDing.caf'
} ).delay( minute * 60 * 12)
  .priority( 'high' )
  .save();



job.on( 'complete', function () {
  console.log( 'renewal job completed' );
} );



jobs.process( 'parseCloud', function ( job, done ) {

      var pushQuery = new Parse.Query(Parse.Installation);
      pushQuery.equalTo('username', request.params.targetUsername);

      Parse.Push.send({
        where: pushQuery, // Set our Installation query                                                                                                                                                              
        data: {
          alert: job.data.alert,
          badge: job.data.badge,
          sound: job.data.sound
        },   
      }, { success: function() {

        console.log("#### PUSH OK");
        done();
      }, error: function(error) {
        console.log("#### PUSH ERROR" + error.message);
         done();
      }, useMasterKey: true});

} );

// start the UI
kue.app.listen( 3000 );
console.log( 'UI started on port 3000' );
于 2016-05-09T21:40:41.243 回答