-
Notifications
You must be signed in to change notification settings - Fork 2
/
app.js
49 lines (38 loc) · 1.07 KB
/
app.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
//require('newrelic');
var cluster = require('cluster');
/*
require('nodetime').profile({
accountKey: 'c2087d25f074a96e5e842cb25d957f2a58d6cba1',
appName: 'Pagetty'
});
*/
if (cluster.isMaster) {
var stamp = new Date().getTime();
var worker_env = {build: stamp};
var cpus = require('os').cpus().length;
//cpus = 1;
console.log('Starting cluster master with ' + cpus + ' workers');
// Fork workers.
for (var i = 0; i < cpus; i++) {
cluster.fork(worker_env);
}
// When a worker dies, launch another one.
cluster.on('exit', function(worker, code, signal) {
console.log('Worker ' + worker.process.pid + ' died, starting another one.');
cluster.fork(worker_env);
});
}
else {
console.log('Starting worker #' + cluster.worker.id);
var broadway = require('broadway');
var app = new broadway.App();
app.worker = cluster.worker;
app.build = process.env.build;
// Load plugins.
app.use(require('./plugins/main.js'));
app.use(require('./plugins/server.js'));
// Launcher.
app.init(function (err) {
if (err) console.log(err);
});
}