Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Updated API example to work with wf@0.8.3/wf-redis-backend@0.8.0

  • Loading branch information...
commit 935346a38ba736be1e1967a143fc4ab28d76c4c7 1 parent aa484bb
@kusor authored
Showing with 43 additions and 42 deletions.
  1. +39 −38 api.js
  2. +2 −2 module.js
  3. +2 −2 shared-workflow.js
View
77 api.js
@@ -1,4 +1,4 @@
-// Copyright 2012 Pedro P. Candel <kusorbox@gmail.com>. All rights reserved.
+// Copyright 2013 Pedro P. Candel <kusorbox@gmail.com>. All rights reserved.
// Usage example for node-workflow using the REST API to create
// workflows, queue jobs and obtain the results.
@@ -11,19 +11,19 @@
// `node api.js $login $password`
if (process.argv.length < 4) {
- console.error('Github username and password required as arguments');
- process.exit(1);
+ console.error('Github username and password required as arguments');
+ process.exit(1);
}
-var $login = process.argv[2],
- $password = process.argv[3];
+var $login = process.argv[2];
+var $password = process.argv[3];
var restify = require('restify'),
util = require('util'),
assert = require('assert');
var client = restify.createJsonClient({
- url: 'http://127.0.0.1:8080'
+ url: 'http://127.0.0.1:8080'
});
var aWorkflow = require('./shared-workflow');
@@ -37,38 +37,39 @@ aWorkflow.chain[1].fallback = aWorkflow.chain[1].fallback.toString();
aWorkflow.onerror[0].body = aWorkflow.onerror[0].body.toString();
client.post('/workflows', aWorkflow, function (err, req, res, wf) {
- assert.ifError(err);
- assert.ok(wf.uuid);
- var aJob = {
- target: '/gists',
- workflow: wf.uuid,
- login: $login,
- password: $password
- };
- client.post('/jobs', aJob, function (err, req, res, job) {
assert.ifError(err);
- assert.ok(job);
- assert.equal(job.execution, 'queued');
- assert.ok(job.uuid);
- var intervalId = setInterval(function () {
- client.get('/jobs/' + job.uuid, function (err, req, res, obj) {
+ assert.ok(wf.uuid);
+ var aJob = {
+ target: '/gists',
+ workflow: wf.uuid,
+ login: $login,
+ password: $password
+ };
+ client.post('/jobs', aJob, function (err, req, res, job) {
assert.ifError(err);
- if (obj.execution === 'queued') {
- console.log('Job waiting to be processed');
- } else if (obj.execution === 'running') {
- console.log('Job in progress ...');
- } else {
- console.log('Job finished. Here come the results:');
- console.log(util.inspect(obj, false, 8));
- // Only one workflow with the same name, need to delete it to allow
- // creating it again:
- client.del('/workflows/' + wf.uuid, function (err, req, res, obj) {
- assert.ifError(err);
- clearInterval(intervalId);
- process.exit(0);
- });
- }
- });
- }, 3000);
- });
+ assert.ok(job);
+ assert.equal(job.execution, 'queued');
+ assert.ok(job.uuid);
+ var intervalId = setInterval(function () {
+ client.get('/jobs/' + job.uuid, function (err, req, res, obj) {
+ assert.ifError(err);
+ if (obj.execution === 'queued') {
+ console.log('Job waiting to be processed');
+ } else if (obj.execution === 'running') {
+ console.log('Job in progress ...');
+ } else {
+ console.log('Job finished. Here come the results:');
+ console.log(util.inspect(obj, false, 8));
+ // Only one workflow with the same name, need to delete it
+ // to allow creating it again:
+ client.del('/workflows/' + wf.uuid,
+ function (err, req, res, obj) {
+ assert.ifError(err);
+ clearInterval(intervalId);
+ process.exit(0);
+ });
+ }
+ });
+ }, 3000);
+ });
});
View
4 module.js
@@ -66,8 +66,8 @@ fs.readFile(config_file, 'utf8', function (err, data) {
} else {
console.log('Job finished. Here come the results:');
console.log(util.inspect(obj, false, 8));
- // Only one workflow with the same name, need to delete it
- // to allow creating it again:
+ // Only one workflow with the same name, need to
+ // delete it to allow creating it again:
backend.deleteWorkflow(wf, function (err, res) {
assert.ifError(err);
assert.ok(res);
View
4 shared-workflow.js
@@ -57,8 +57,8 @@ var workflow = module.exports = {
return client.get(
'/gists/' + job.gist_id + '/star',
function (err, req, res, obj) {
- // Indeed, there should be an error here, which will triger our
- // fallback, where we'll add the star to our gist
+ // Indeed, there should be an error here, which will triger
+ // our fallback, where we'll add the star to our gist
if (err) {
return cb(err);
} else {
Please sign in to comment.
Something went wrong with that request. Please try again.