Skip to content

Commit 7fe9521

Browse files
flovilmarthramos
authored andcommitted
Adds documentation for Cloud Jobs (#372)
1 parent 486cee6 commit 7fe9521

File tree

2 files changed

+290
-235
lines changed

2 files changed

+290
-235
lines changed

_includes/cloudcode/cloud-code.md

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,61 @@ If there is an error, the response in the client looks like:
131131
}
132132
```
133133

134+
# Cloud Jobs
135+
136+
Sometimes you want to execute long running functions, and you don't want to wait for the response. Cloud Jobs are just meant for that.
137+
138+
## Define a Job
139+
140+
```javascript
141+
Parse.Cloud.job("myJob", function(request, status) {
142+
// the params passed through the start request
143+
var params = request.params;
144+
// Headers from the request that triggered the job
145+
var headers = request.headers;
146+
147+
// get the parse-server logger
148+
var log = request.log;
149+
150+
// Update the Job status message
151+
status.message("I just started");
152+
doSomethingVeryLong().then(function(result) {
153+
// Mark the job as successful
154+
// success and error only support string as parameters
155+
status.success("I just finished");
156+
}, function(error) {
157+
// Mark the job as errored
158+
status.error("There was an error");
159+
})
160+
});
161+
```
162+
163+
Note that calling `status.success` or `status.error` won't prevent any further execution of the job.
164+
165+
## Running a Job
166+
167+
Calling jobs is done via the REST API and is protected by the master key.
168+
169+
```sh
170+
curl -X POST -H 'X-Parse-Application-Id: appId' -H 'X-Parse-Master-Key: masterKey' https://my-parse-server.com/1/jobs/myJob
171+
```
172+
173+
The response will consist of an empty body and contain the `X-Parse-Job-Status-Id: a1c3e5g7i9k` header. With the _JobStatus's objectId that has just been created.
174+
175+
You can pass some data alongside the call if you want to customize the job execution.
176+
177+
## Scheduling a Job
178+
179+
We don't support at the moment job scheduling and highly recommend to use a 3rd party system for scheduling your jobs.
180+
181+
- On [AWS Elastic Beanstalk](http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/using-features-managing-env-tiers.html#worker-periodictasks)
182+
- On [Google App Engine](https://cloud.google.com/appengine/docs/flexible/nodejs/scheduling-jobs-with-cron-yaml)
183+
- On [Heroku](https://devcenter.heroku.com/articles/scheduler#scheduling-jobs)
184+
185+
## Viewing Jobs
186+
187+
Viewing jobs is currently not supported on parse-dashboard, but you can query the _JobStatus class with a masterKey call to fetch your recent jobs.
188+
134189
# beforeSave Triggers
135190

136191
## Implementing validation

0 commit comments

Comments
 (0)