forked from RackHD/on-taskgraph
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
80 lines (73 loc) · 2.62 KB
/
index.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
// Copyright 2016, EMC, Inc.
'use strict';
var di = require('di'),
_ = require('lodash'),
core = require('on-core')(di),
injector = new di.Injector(
_.flattenDeep([
core.injectables,
core.workflowInjectables,
require('on-tasks').injectables,
require('./lib/task-graph-runner.js'),
require('./lib/task-runner.js'),
require('./lib/loader.js'),
require('./lib/task-scheduler.js'),
require('./lib/lease-expiration-poller.js'),
require('./lib/service-graph.js'),
require('./lib/completed-task-poller.js'),
require('./lib/rx-mixins.js')
])
),
taskGraphRunner = injector.get('TaskGraph.Runner'),
logger = injector.get('Logger').initialize('TaskGraph');
var options = {
runner: true,
scheduler: true
};
if (_.contains(process.argv, '-s') || _.contains(process.argv, '--scheduler')) {
options.runner = false;
} else if (_.contains(process.argv, '-r') || _.contains(process.argv, '--runner')) {
options.scheduler = false;
}
if (_.contains(process.argv, '-d') || _.contains(process.argv, '--domain')) {
_.reduce(process.argv, function(lastArg, arg) {
if (lastArg === '-d' || lastArg === '--domain') {
if (_.contains(['-s', '--scheduler', '-r', '--runner'], arg)) {
console.error('\nNo value for domain specified!');
process.exit(1);
}
options.domain = arg;
}
return arg;
});
}
if (_.last(process.argv) === '-d' || _.last(process.argv) === '--domain') {
console.error('\nNo value for domain specified!');
process.exit(1);
}
taskGraphRunner.start(options)
.then(function () {
logger.info('Task Graph Runner Started.');
})
.catch(function(error) {
//NOTE(heckj): I'm unclear why this is on the console directly and not
// using a logger. Would expect this to be logger.critical(), but
// leaving as is because I don't know the implications.
console.error(error.message || error.details);
console.error(error.stack || error.rawStack);
// logger.critical('Task Graph Runner Startup Error.', { error: error });
process.nextTick(function() {
process.exit(1);
});
});
process.on('SIGINT', function() {
taskGraphRunner.stop()
.catch(function(error) {
logger.critical('Task Graph Runner Shutdown Error.', { error: error });
})
.finally(function() {
process.nextTick(function() {
process.exit(1);
});
});
});