parse-server icon indicating copy to clipboard operation
parse-server copied to clipboard

Is there a way to implement scheduled push?

Open baymitchell12 opened this issue 10 years ago • 11 comments

Scheduled push is crucial to many applications. I know that scheduled push is not currently supported on parse-server, but I am wondering if there is a way to implement it now OR when it might be supported (scheduled push implementation is listed under future improvements).

baymitchell12 avatar Apr 25 '16 19:04 baymitchell12

As with scheduled background jobs, the best way to implement scheduled push notifications on Parse Server is to use a cron job or your favorite scheduling npm.

hramos avatar Apr 25 '16 21:04 hramos

@hramos I have an application in which users must send other users information which they will be notified about in the future. The time intervals aren't always the same and users can send the information whenever they please. I don't think a scheduling npm is applicable considering that the time intervals are randomized and users can send the information at any time. This task was easily accomplished with push_time in cloud code but that isn't currently supported. Is there any other way around this issue or am I misinformed that a scheduling npm isn't applicable in this situation. (NOTE: I'm not running the server locally either. My parse-server is deployed on mLab.)

baymitchell12 avatar Apr 26 '16 00:04 baymitchell12

You can use kue to define specific scheduled jobs with any time interval you want. This is what I use.

AmbroiseCollon avatar Apr 26 '16 11:04 AmbroiseCollon

@baymitchell12 mLab only hosts your database. Your Parse Server must be running elsewhere, where you should have at least the option to use kue like @AmbroiseCollon suggested.

hramos avatar Apr 26 '16 15:04 hramos

@hramos My server is a modified fork of the parse server example deployed through heroku with mLab hosting the database. So kue would be a viable option?

baymitchell12 avatar Apr 26 '16 17:04 baymitchell12

Yes, you can expand the Parse server example project to implement this functionality.

hramos avatar Apr 26 '16 17:04 hramos

@AmbroiseCollon Can you share me how to implement Kue with Parse-server? I am building a system where it will make auto payment each month to my users (on 28th of each month). I wrote a cloud code method in main.js to send out payment already, but I don't know how to integrate Kue to call that method.

tran-huy-phuc avatar Jun 06 '16 15:06 tran-huy-phuc

Here is a draft. I don't have time to finish it right now. Do not hesitate to copy paste it and finish it for me or to write suggestions. It should put you on the right path at least. https://medium.com/@ambroisecollon/7754cd31d41e

AmbroiseCollon avatar Jun 14 '16 13:06 AmbroiseCollon

@AmbroiseCollon Do you have any code available using kue? Can't get to get it to work.

lucasputer avatar Jun 27 '16 20:06 lucasputer

index.js

var kue = require('kue')
var redisUrl = process.env.REDIS_URL 
kue.createQueue({ redis: redisUrl })
app.use('/kue', kue.app) // For the kue dashboard

cloud file

var due = require('kue')
var redisUrl = process.env.REDIS_URL
var jobs = kue.createQueue({ redis: redisUrl })

/**
 * Create the job for expiring round after 24h
*/
function createRoundExpiredJob(round) {
    jobs.create('roundExpired', {
        objectId: round.id
    })
    .removeOnComplete(true)
    .delay(round.createdAt.addADay())
    .save()
}

queue.js

var kue = require('kue')
var redisUrl = process.env.REDIS_URL
var jobs = kue.createQueue({ redis: redisUrl })

var Parse = require('parse/node')
Parse.initialize('masterKey')
Parse.serverURL = yourServerUrl

/**
 * Process the job for ending a round after 24h
*/
jobs.process('roundExpired', function (job, done) {
    // Your parse related code and when finished (in save callback for instance):
       done()
})

Procfile

web:    node index.js
worker: node queue.js

AmbroiseCollon avatar Jun 29 '16 12:06 AmbroiseCollon

@AmbroiseCollon Thanks a lot!

lucasputer avatar Jun 30 '16 09:06 lucasputer