Skip to content
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

POST /job API #116

Merged
merged 10 commits into from Nov 16, 2012
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 20 additions & 0 deletions Readme.md
Expand Up @@ -312,6 +312,26 @@ kue.app.set('title', 'My Application');
$ curl -X DELETE http://local:3000/job/2
{"message":"job 2 removed"}

### POST /job

Create a job:

$ curl -H "Content-Type: application/json" -X POST -d \
'{
"type": "email",
"data": {
"title": "welcome email for tj",
"to": "tj@learnboost.com",
"template": "welcome-email"
},
"options" : {
"attempts": 5,
"priority": "high"
}
}' http://localhost:3000/job
{"message":"job 3 created"}


## Parallel Processing With Cluster

The example below shows how you may use [Cluster](http://learnboost.github.com/cluster) to spread the job processing load across CPUs. By default cluster will create one worker per CPU, however you can specify this number via `.set('workers', N)`.
Expand Down
1 change: 1 addition & 0 deletions lib/http/index.js
Expand Up @@ -61,6 +61,7 @@ app.get('/job/:id/log', provides('json'), json.log);
app.put('/job/:id/state/:state', provides('json'), json.updateState);
app.put('/job/:id/priority/:priority', provides('json'), json.updatePriority);
app.del('/job/:id', provides('json'), json.remove);
app.post('/job', provides('json'), express.bodyParser(), json.createJob);

// routes

Expand Down
23 changes: 23 additions & 0 deletions lib/http/routes/json.js
Expand Up @@ -122,6 +122,29 @@ exports.job = function(req, res){
});
};

/**
* Create a job.
*/

exports.createJob = function(req, res) {
if (!req.body.type)
return res.send({ error: 'Must provide job type' }, 400);

var job = new Job(req.body.type, req.body.data || {});
var options = req.body.options;
if (options && options.attempts)
job.attempts(parseInt(options.attempts));
if (options && options.priority)
job.priority(options.priority);

job.save(function(err, resp) {
if (err)
return res.send({ error: err.message }, 500);
res.send({ message: 'job ' + job.id + ' created' });
});
};


/**
* Remove job :id.
*/
Expand Down