forked from pipedrive/kardia
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
39 lines (32 loc) · 1.01 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
(function() {
'use strict';
var currentStatus = null,
cluster = require('cluster'),
Status = require(__dirname + '/lib/status.js');
// if running on a cluster worker, we assume the master already has Kardia started, thus we
// instantiate a wrapper instance right-away
if (!cluster.isMaster) {
currentStatus = new Status({});
module.exports = currentStatus;
} else {
var startHandler = function(config) {
if (currentStatus === null) {
currentStatus = new Status(config);
if (!currentStatus._instanceId) {
currentStatus._instanceId = Date.now()+'.'+Math.round(Math.random()*1000);
}
currentStatus.on('serverStopped', function() {
currentStatus = null;
module.exports = { start: startHandler };
});
if (cluster.isMaster) {
currentStatus.startServer();
}
module.exports = currentStatus;
}
return currentStatus;
};
// otherwise only expose the .start() command, which in turn returns the currentStatus.
module.exports.start = startHandler;
}
})();