forked from sirikon/venue
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
32 lines (26 loc) · 915 Bytes
/
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
const cluster = require('cluster');
const debug = process.env.NODE_ENV !== 'production';
const PORT = process.env.PORT || 8000;
function getNumWorkers() {
return require('os').cpus().length;
}
if (cluster.isMaster && !debug) {
const numWorkers = getNumWorkers();
console.log(`Initializing with ${numWorkers} workers.\nWill listen on port ${PORT}.`);
for(let i = 0; i < numWorkers; i++) {
cluster.fork();
}
cluster.on('online', function(worker) {
console.log(`Worker ${worker.process.pid} is online`);
});
cluster.on('exit', function(worker, code, signal) {
console.log(`Worker ${worker.process.pid} died with code: ${code}, and signal: ${signal}`);
if (!debug) {
cluster.fork();
}
});
} else {
const talks = require('./src/data/talks');
const app = require('./src/app')(talks);
app.listen(PORT, '0.0.0.0');
}