primary worker support, and added notif pruning to primary worker jobs

v1.18.x
Julian Lam 11 years ago
parent 2efb816da3
commit 7255ce3dbe

@ -68,6 +68,11 @@ Loader.init = function() {
}); });
}); });
break; break;
case 'listening':
if (message.primary) {
Loader.primaryWorker = parseInt(worker.id, 10);
}
break;
case 'user:connect': case 'user:connect':
case 'user:disconnect': case 'user:disconnect':
notifyWorkers(worker, message); notifyWorkers(worker, message);
@ -106,7 +111,11 @@ Loader.init = function() {
console.log('[cluster] Child Process (' + worker.process.pid + ') has exited (code: ' + code + ')'); console.log('[cluster] Child Process (' + worker.process.pid + ') has exited (code: ' + code + ')');
if (!worker.suicide) { if (!worker.suicide) {
console.log('[cluster] Spinning up another process...') console.log('[cluster] Spinning up another process...')
cluster.fork();
var wasPrimary = parseInt(worker.id, 10) === Loader.primaryWorker;
cluster.fork({
handle_jobs: wasPrimary
});
} }
}); });
@ -116,9 +125,14 @@ Loader.init = function() {
}; };
Loader.start = function() { Loader.start = function() {
Loader.primaryWorker = 1;
for(var x=0;x<numCPUs;x++) { for(var x=0;x<numCPUs;x++) {
// Only the first worker sets up templates/sounds/jobs/etc // Only the first worker sets up templates/sounds/jobs/etc
cluster.fork({ cluster_setup: x === 0 }); cluster.fork({
cluster_setup: x === 0,
handle_jobs: x ===0
});
} }
} }

@ -56,6 +56,6 @@ module.exports = function(app, middleware, controllers) {
}); });
router.get('/test', function(req, res) { router.get('/test', function(req, res) {
res.redirect(404); process.exit(0);
}); });
}; };

@ -39,9 +39,9 @@ if(nconf.get('ssl')) {
logger.init(app); logger.init(app);
auth.registerApp(app); auth.registerApp(app);
emailer.registerApp(app); emailer.registerApp(app);
notifications.init();
if (cluster.isWorker && process.env.cluster_setup === 'true') { if (cluster.isWorker && process.env.handle_jobs === 'true') {
notifications.init();
user.startJobs(); user.startJobs();
} }
@ -140,7 +140,8 @@ if(nconf.get('ssl')) {
if (process.send) { if (process.send) {
process.send({ process.send({
action: 'listening', action: 'listening',
bind_address: bind_address bind_address: bind_address,
primary: process.env.handle_jobs === 'true'
}); });
} }
}); });

Loading…
Cancel
Save