Skip to content

Node.js based forum software built for the modern web

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

Julian Lam7255ce3dbecf
diff --git a/loader.js b/loader.js
index c5f325ad9d..42d198c047 100644
--- a/loader.js
+++ b/loader.js
@@ -68,6 +68,11 @@ Loader.init = function() {
});
});
break;
+ case 'listening':
+ if (message.primary) {
+ Loader.primaryWorker = parseInt(worker.id, 10);
+ }
+ break;
case 'user:connect':
case 'user:disconnect':
notifyWorkers(worker, message);
@@ -106,7 +111,11 @@ Loader.init = function() {
console.log('[cluster] Child Process (' + worker.process.pid + ') has exited (code: ' + code + ')');
if (!worker.suicide) {
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.primaryWorker = 1;
+
for(var x=0;x<numCPUs;x++) {
// 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
+ });
}
}
diff --git a/src/routes/debug.js b/src/routes/debug.js
index 584a70a6b6..4cac674955 100644
--- a/src/routes/debug.js
+++ b/src/routes/debug.js
@@ -56,6 +56,6 @@ module.exports = function(app, middleware, controllers) {
});
router.get('/test', function(req, res) {
- res.redirect(404);
+ process.exit(0);
});
};
diff --git a/src/webserver.js b/src/webserver.js
index b47217d419..fa4b1e7fdc 100644
--- a/src/webserver.js
+++ b/src/webserver.js
@@ -39,9 +39,9 @@ if(nconf.get('ssl')) {
logger.init(app);
auth.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();
}
@@ -140,7 +140,8 @@ if(nconf.get('ssl')) {
if (process.send) {
process.send({
action: 'listening',
- bind_address: bind_address
+ bind_address: bind_address,
+ primary: process.env.handle_jobs === 'true'
});
}
});