-
Notifications
You must be signed in to change notification settings - Fork 0
/
wrapper.js
36 lines (27 loc) · 802 Bytes
/
wrapper.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
var config = require('./../config');
var jobName = process.argv[2];
var logger = require('../../../lib/logger')('jobwrapper - "'+ jobName +'"');
process.on('uncaughtException', result);
if (!config[jobName]) {
throw new Error('Job "'+ jobName +'" does not exists');
}
var job = require('../'+ jobName);
if (typeof(job.Run) != 'function') {
throw new TypeError('Job "'+ jobName +'" does not have method Run');
}
function result(err, result){
if (err) {
err = {
name: err.name,
message: err.message,
stack: err.stack
};
}
arguments[0] = err;
process.send(Array.prototype.slice.call(arguments));
process.disconnect();
}
process.on('message', function(args) {
args.push(result);
job.Run.apply(null, args);
});