Comparing version 0.4.17 to 0.4.18
@@ -85,2 +85,3 @@ /* | ||
heartbeatInterval: options.heartbeatInterval, | ||
maxHeartbeatDelay: options.maxHeartbeatDelay, | ||
emitter: self | ||
@@ -87,0 +88,0 @@ }); |
@@ -52,2 +52,4 @@ /* | ||
this.options.maxHeartbeatDelay = options.maxHeartbeatDelay || 3*60000; //default 3 mins | ||
this._heartbeats = []; | ||
@@ -154,5 +156,8 @@ | ||
if(message.type === 'heartbeat'){ | ||
if(message.pid != process.pid){ | ||
self._heartbeats.push(message);//must append to the tail | ||
// update the last heartbeat time for the worker | ||
var workerStats = self.stats.workers[message.pid]; | ||
//console.log('heartbeat ' + process.pid); | ||
workerStats.lastHeartbeatAt= Date.now(); | ||
} | ||
@@ -199,2 +204,19 @@ | ||
self.lastTime = Date.now(); | ||
// Check the last heartbeat time of all the workers | ||
_.each(self.stats.workers, function (workerStats, pid) { | ||
var now = Date.now(); | ||
if (now - workerStats.lastHeartbeatAt> self.options.maxHeartbeatDelay) { | ||
// this worker hasn't been sending heartbeat for maxHeartbeatDelay | ||
log(util.format('[Cluster2] Detected worker%d is not responsive for %d', pid, now - workerStats.lastHeartbeatAt)); | ||
var deathQueue = require('./misc').deathQueue; | ||
deathQueue(self.workers[pid], self.emitter, function () { | ||
// create a successor | ||
var successor = self.createWorker(); | ||
self.workers[successor.pid] = successor; | ||
log(util.format('[Cluster2] Created a new worker with pid %d', successor.pid)); | ||
return successor; | ||
}); | ||
} | ||
}); | ||
@@ -464,2 +486,4 @@ }, self.options.heartbeatInterval || 60000); | ||
// put the emitter in the process | ||
process.emitter = self.emitter; | ||
self.emitter.emit(signal, { | ||
@@ -646,2 +670,4 @@ pid: process.pid, | ||
}, self.options.heartbeatInterval || 60000); | ||
// put the heartbeat interval id in the process context | ||
process.heartbeat = heartbeat; | ||
@@ -648,0 +674,0 @@ _.each(apps, function(app){ |
@@ -8,3 +8,3 @@ { | ||
"name": "cluster2", | ||
"version": "0.4.17", | ||
"version": "0.4.18", | ||
"repository": { | ||
@@ -11,0 +11,0 @@ "type": "git", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1319655
1846
30