Skip to content

Is there a way to implement scheduled push? #1628

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
baymitchell12 opened this issue Apr 25, 2016 · 11 comments
Closed

Is there a way to implement scheduled push? #1628

baymitchell12 opened this issue Apr 25, 2016 · 11 comments

Comments

@baymitchell12
Copy link

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).

@hramos
Copy link
Contributor

hramos commented Apr 25, 2016

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.

@baymitchell12
Copy link
Author

baymitchell12 commented Apr 26, 2016

@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.)

@AmbroiseCollon
Copy link

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

@hramos
Copy link
Contributor

hramos commented Apr 26, 2016

@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.

@baymitchell12
Copy link
Author

@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?

@hramos
Copy link
Contributor

hramos commented Apr 26, 2016

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

@hramos hramos closed this as completed Apr 26, 2016
@tran-huy-phuc
Copy link

@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.

@AmbroiseCollon
Copy link

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

@lucasputer
Copy link

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

@AmbroiseCollon
Copy link

AmbroiseCollon commented Jun 29, 2016

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

@lucasputer
Copy link

@AmbroiseCollon Thanks a lot!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants