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

Cloud Jobs Guidance

Open anthonysg opened this issue 10 years ago • 32 comments

Hello, from what I understand, cloud jobs are not working in parse-server. It states the following in the migration docs:

Jobs

There is no Job functionality in Parse Server. If you have scheduled jobs, port them over to a self-hosted solution using a wide variety of open source job queue projects. A popular one is kue. Alternatively, if your jobs are simple, you could use a cron job.

I am wondering if a tutorial could be made showing how to modify already-made cloud jobs to run using kue. Either that or it would be really nice if somebody could implement this functionality.

anthonysg avatar Feb 01 '16 22:02 anthonysg

I agree a guide would be handy. We've been leaning towards telling developers to build node scripts for this and trigger them with a cron scheduler... but yeah, an example would be great.

gfosco avatar Feb 01 '16 23:02 gfosco

My Cloud code (main.js) contains a Job function: Parse.Cloud.job("jobRequestForValidation", function(request, status) { ... ...});

This caused failure of deployment of my app on Heroku.

So I had to remove the Job from the main.js so that deployment was successful.

grassland-curing-cfa avatar Feb 19 '16 06:02 grassland-curing-cfa

Going to close this for lack of activity. Guidance for cloud jobs will likely vary based on the deployment platform of choice (i.e. the Scheduler addon for heroku, or some cron script for a VPS).

gfosco avatar Feb 26 '16 10:02 gfosco

Hi, I'm setting up a tutorial on Kue + Heroku. In order to finish it, I need help on this issue #1078. Thanks and I hope you'll like it ^^!

AmbroiseCollon avatar Mar 17 '16 15:03 AmbroiseCollon

I use the following for simple jobs:

if (!Parse.Cloud.job) {
    Parse.Cloud.job = function(name, func) { 
        app.get("/jobs/" + name, func);
    };
} 

Where app is my express instance in the same scope. This function exposes jobs as GET endpoints from my server. For instance, a job called MyJob could be run by hitting /jobs/MyJob.

mdtempalert avatar Mar 25 '16 14:03 mdtempalert

Does anyone know if there are any news on any tutorials for this. I keep hitting rode blocks trying to set this up.

rendragon83 avatar Apr 07 '16 17:04 rendragon83

I have to kick this as well, I have seen some info on jobs but no wiki or docs on the best way or best practices for this..

gateway avatar Oct 12 '16 18:10 gateway

Parse.Cloud.Job is exposed.

Every job will be exposed through: /jobs/:jobName and protected by the masterKey access.

Job status is recorded in the _JobStatus whenever the jobs starts, ends, error etc... as the old jobs would do.

Jobs are not scheduled, you should handle scheduling calling the job HTTP endpoint yourself (with the masterKey).

You should be able to run the jobs from the parse-dashboard to test your endpoints and see the status of your jobs.

flovilmart avatar Oct 12 '16 20:10 flovilmart

@flovilmart thanks for your reply, is their some sort of priority we can define for jobs and whats the expected time out that a job might see. I can early have another server do the scheduling via cron and using CURL to run the job. How would be pull _JobStatus back to see the progress, completion etc?

gateway avatar Oct 12 '16 20:10 gateway

There is no priority as there is no schedule, the Job is just the same thing a a cloud function, the only difference is that it's status can be updated for success, error and messages.

You can read the job status in the dashboard or make a query on it "_JobStatus".

flovilmart avatar Oct 12 '16 20:10 flovilmart

Jobs are not scheduled, you should handle scheduling calling the job HTTP endpoint yourself (with the masterKey).

So how should we do this if we want the job(s) to be scheduled? (Open to anyone's answer) I am using google app engine, and I understand there is some sort of scheduler but it is not cron-based. Would that work?

noder199 avatar Oct 13 '16 04:10 noder199

You can use app engine cron.yaml To schedule the calls to the jobs end points.

flovilmart avatar Oct 13 '16 11:10 flovilmart

I should of asked, but do jobs time out after x minutes?

gateway avatar Oct 20 '16 00:10 gateway

This was pretty difficult for me to figure out so I am just going to post a full url example here in hopes it saves someone else time.

Basically I used Postman to Post to a url like http://localhost:1337/parse/jobs/:jobName while having the following headers set. X-Parse-Application-Id and X-Parse-Master-Key.

afgarcia86 avatar Oct 27 '16 16:10 afgarcia86

@gateway they don't @afgarcia86 that is how to run them, use the same method in a scheduler if you need to.

flovilmart avatar Oct 27 '16 16:10 flovilmart

FYI, I've successfully used a web cron service as an external scheduler so that I didn't have to maintain an additional bit of infrastructure.

https://www.setcronjob.com

P.S. - I have no affiliation w/ this service. It's just the one I happened to use and it worked for me.

chadpav avatar Jan 26 '17 20:01 chadpav

@flovilmart - for AWS worker tier, cron.yaml is to be formatted as:

version: 1 cron:

  • name: "backup-job" url: "/backup" schedule: "0 */12 * * *"

Where would I include the parse app id and masterkey? Would it look like below?

url: "/backup" headers: { X-Parse-Application-Id: appId X-Parse-Master-Key: masterKey } schedule: "0 */12 * * *"

Any guidance would be greatly appreciated!

devKC avatar Mar 12 '17 21:03 devKC

On Google cloud, I'm using something similar with app engine CRON. I have deployed a very simple JavaScript web app that listen on /job/:jobName and forwards the HTTP call to parse server. This way, I use app engine cron for scheduling as I can't pass the headers either.

You should probably look for something similar on AWS.

flovilmart avatar Mar 12 '17 23:03 flovilmart

@flovilmart - just checking, when you are forwarding the HTTP call to parse server, are you passing along the app_id/master_key values in headers by using something like headers option for require('request')? If so, how secure is it to send the request with keys in the headers? I would assume I wouldn't hardcode the key values in the headers options but use env var, but since the values are being sent in the post request I was wondering if it is recommended to protect the values, i.e. encryption, etc.

devKC avatar Mar 16 '17 14:03 devKC

I make HTTPS requests from the 'worker' so yes I pass my masterKey in the header.

flovilmart avatar Mar 16 '17 15:03 flovilmart