-
Notifications
You must be signed in to change notification settings - Fork 1
/
execJob.js
74 lines (62 loc) · 1.65 KB
/
execJob.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
/**
* Executes a knowhow Job
*/
var KnowhowShell = require('./knowhow-shell.js');
var knowhowShell = new KnowhowShell();
var EventEmitter = require('events').EventEmitter;
var eventEmitter = new EventEmitter();
exports.executeJob = function(job) {
knowhowShell.executeJob(npmInitJob, function(err) {
console.log("done...........");
if (err) {
console.log(err.message);
console.log(err.stack);
throw err;
}
});
}
var events = ['job-complete', 'job-error', 'job-cancel','job-update','execution-start', 'execution-error','execution-password-prompt', 'execution-complete', 'execution-output'];
/**
* listens for and rebroadcast
*/
var listenForEvents = function(knowhowShell,events) {
for (index in events) {
var event = events[index];
//console.log(event);
knowhowShell.on(event, function(data) {
//console.log("EVENT: "+this.event);
data.eventType = this.event;
delete data.timeout;
delete data.progressCheck;
//console.log(data);
try {
if (process) {
process.send(data);
}
} catch(err) {
process.exit(1);
}
}.bind({event:event}));
}
}
console.log("knowhow job process starting...");
if (!process.argv[2]) {
console.error("no job specified");
process.exit(1);
} else {
var job = JSON.parse(process.argv[2]);
var EventEmitter = new EventEmitter();
listenForEvents(knowhowShell,events);
knowhowShell.executeJob(job, function(err, scriptRuntime) {
if(err) {
job.eventType="job-error";
process.send(job);
process.exit(1);
}
console.log(job.id+" subprocess complete");
job.eventType="subprocess-complete";
job.scriptRuntime = scriptRuntime;
process.send(job);
process.exit(0);
});
}