How to schedule a job with kue on parse-server?

后端 未结 1 1365
故里飘歌
故里飘歌 2021-01-16 17:38

I have a parse-server deployed with Heroku (from my GitHub repo) and hosted by mongoLab. I am attempting to send scheduled push notifications within my app and kue seems to

相关标签:
1条回答
  • 2021-01-16 18:43

    Here is an example how you can accomplish scheduling this task with kue only once at a specific time in the future: (after 12 hours)

    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' );
    
    0 讨论(0)
提交回复
热议问题