-
Notifications
You must be signed in to change notification settings - Fork 0
/
serviceInfrastructure.js
51 lines (42 loc) · 1.3 KB
/
serviceInfrastructure.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
'use strict';
const defaults = {
name: 'completeInfrasture'
};
var all;
module.exports = all = function (options) {
const seneca = this;
const extend = seneca.util.deepextend;
const opts = extend(defaults, options);
seneca.use(__dirname + '/user/service');
seneca.use(__dirname + '/systems/service');
seneca.use(__dirname + '/applications/service');
seneca.use(__dirname + '/metrics/service');
seneca.use(__dirname + '/graphs/service');
seneca.use(__dirname + '/stats-generator/service');
seneca.add({ init: opts.name }, function (args, ready) {
console.log('init', defaults.name, '...');
// do some init work
setTimeout(ready, 100);
});
seneca.ready(function(err) {
console.log(opts.name, err || 'rdy ✓');
});
seneca.add('role:seneca,cmd:close', function (close_msg, done) {
// do some cleanup or something
console.log('bye bye from', defaults.name);
this.prior(close_msg, done);
});
if (opts.startListening) {
seneca.listen();
}
return {
name: opts.name
};
};
if (require.main === module) {
console.log('called directly');
const seneca = require('seneca')();
seneca.use(all, { startListening: true });
} else {
console.log('required as a module');
}