Permalink
Browse files

fix auto-respawned workers not getting options

  • Loading branch information...
1 parent c215181 commit 43d7b1dbb81c4192fa5a4435c26e941af3ff1353 Carlos Rodriguez committed Aug 29, 2012
Showing with 8 additions and 3 deletions.
  1. +8 −3 bin/buffet.js
View
@@ -48,13 +48,19 @@ cluster.setupMaster({
exec: require('path').resolve(__dirname, '../lib/worker.js')
});
+function fork () {
+ var worker = cluster.fork();
+ worker.send({cmd: 'BUFFET_OPTIONS', options: options});
+ return worker;
+}
+
// Auto-respawn
cluster.on('exit', function (worker, code, signal) {
- cluster.fork();
+ fork();
});
for (var i = 0; i < options.threads; i++) {
- var worker = cluster.fork();
+ var worker = fork();
worker.on('message', function (message) {
if (message.cmd === 'BUFFET_UP') {
workerCount++;
@@ -63,5 +69,4 @@ for (var i = 0; i < options.threads; i++) {
}
}
});
- worker.send({cmd: 'BUFFET_OPTIONS', options: options});
}

0 comments on commit 43d7b1d

Please sign in to comment.