-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex-cluster.js
More file actions
45 lines (37 loc) · 938 Bytes
/
Copy pathindex-cluster.js
File metadata and controls
45 lines (37 loc) · 938 Bytes
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
/**
* Primary file for API
*
*/
//Dependencies
var server = require('./lib/server');
var workers = require('./lib/workers');
var cli = require('./lib/cli');
var cluster = require('cluster');
var os = require('os');
//Declare app
var app = {};
//If we are the master thread, start the background workers and CLI
app.init = (callback) => {
if(cluster.isMaster) {
//start workers
workers.init();
//Start the CLI, but make sure it starts last
setTimeout(()=>{
cli.init();
callback();
},50);
// Fork the process
for(var i = 0; i < os.cpus().length;i++){
cluster.fork();
}
} else {
//If we are not the master thread, start the hhtp server
//Init function
server.init();
}
};
//Self invoking only if you require directly
if(require.main === module) {
app.init(()=>{});
};
module.exports = app;