-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathmodule.js
83 lines (72 loc) · 2.86 KB
/
module.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
// Copyright 2014 Pedro P. Candel <[email protected]>. All rights reserved.
// Usage example for wf using it as a node module to create
// workflows, queue jobs and obtain the results.
// NOTE it needs `./node_modules/.bin/workflow-runner` running before you
// run this file.
// Call from parent directory with:
// `node module.js $login $password`
if (process.argv.length < 4) {
console.error('Github username and password/token required as arguments');
process.exit(1);
}
var $login = process.argv[2];
var $password = process.argv[3];
var util = require('util');
var assert = require('assert');
var path = require('path');
var fs = require('fs');
var Factory = require('wf').Factory;
var aWorkflow = require('./shared-workflow');
aWorkflow.name = 'a gist created using wf module';
var config_file = path.normalize(__dirname + '/config.json');
fs.readFile(config_file, 'utf8', function (err, data) {
if (err) {
throw err;
}
var config = JSON.parse(data),
Backend = require(config.backend.module),
backend = new Backend(config.backend.opts),
factory;
backend.init(function () {
factory = Factory(backend);
factory.workflow(aWorkflow, function (err, wf) {
assert.ifError(err);
assert.ok(wf);
var aJob = {
target: '/gists',
workflow: wf.uuid,
params: {
login: $login,
password: $password
}
};
factory.job(aJob, function (err, job) {
assert.ifError(err);
assert.ok(job);
assert.equal(job.execution, 'queued');
assert.ok(job.uuid);
var intervalId = setInterval(function () {
backend.getJob(job.uuid, function (err, 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:
backend.deleteWorkflow(wf, function (err, res) {
assert.ifError(err);
assert.ok(res);
clearInterval(intervalId);
process.exit(0);
});
}
});
}, 3000);
});
});
});
});