Skip to content
This repository has been archived by the owner on Jun 2, 2024. It is now read-only.

Commit

Permalink
add restart, fixed #346
Browse files Browse the repository at this point in the history
  • Loading branch information
dead-horse committed Jun 4, 2014
1 parent 1f219cb commit 8b955ad
Showing 1 changed file with 23 additions and 4 deletions.
27 changes: 23 additions & 4 deletions dispatch.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,18 @@ var childProcess = require('child_process');
var syncPath = path.join(__dirname, 'sync');

if (config.enableCluster) {
forkWorker();
if (config.syncModel !== 'none') {
forkSyncer();
}
} else {
require(workerPath);
if (config.syncModel !== 'none') {
require(syncPath);
}
}

function forkWorker() {
cluster.setupMaster({
exec: workerPath
});
Expand All @@ -50,9 +62,16 @@ if (config.enableCluster) {
for (var i = 0; i < config.numCPUs; i++) {
cluster.fork();
}
}

childProcess.fork(syncPath);
} else {
require(workerPath);
require(syncPath);
function forkSyncer() {
var syncer = childProcess.fork(syncPath);
syncer.on('exit', function (code, signal) {
var err = new Error(util.format('syncer %s died (code: %s, signal: %s, stdout: %s, stderr: %s)',
syncer.pid, code, signal, syncer.stdout, syncer.stderr));
err.name = 'SyncerWorkerDiedError';
console.error('[%s] [master:%s] syncer exit: %s: %s',
Date(), process.pid, err.name, err.message);
setTimeout(forkSyncer, 1000);
});
}

0 comments on commit 8b955ad

Please sign in to comment.