Skip to content

Commit

Permalink
terminated workers must restart automatically
Browse files Browse the repository at this point in the history
  • Loading branch information
theganyo committed Jun 14, 2019
1 parent af8c71a commit eab32fd
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 14 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,5 @@ default.yaml.bak
test-token.txt
env.sh
foo

.nyc_output
20 changes: 6 additions & 14 deletions cli/lib/reload-cluster.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,8 @@ var ReloadCluster = (file, opt) => {
opt.workerReadyWhen = opt.workerReadyWhen || 'listening';
opt.args = opt.args || [];
opt.log = opt.log || {respawns: true};
opt.respawnIntervalManager = RespawnIntervalManager({minRespawnInterval: opt.minRespawnInterval});

var logger = opt.logger || console;
var respawnIntervalManager = RespawnIntervalManager({minRespawnInterval: opt.minRespawnInterval});
var respawnerTimers = RespawnTimerList();
var readyEvent = opt.workerReadyWhen == 'started' ? 'online' : opt.workerReadyWhen == 'listening' ? 'listening' : 'message';
var readyCommand = 'ready';
Expand Down Expand Up @@ -95,16 +94,11 @@ var ReloadCluster = (file, opt) => {

removeWorkerFromActiveWorkers(worker);

var now = Date.now();

//test if the worker was able to load
// respawn worker
try {
//test if the worker was able to load
if (typeof respawnIntervalManager.getIntervalForNextSpawn == 'function') {
var interval = respawnIntervalManager.getIntervalForNextSpawn(now);

var interval = opt.respawnIntervalManager.getIntervalForNextSpawn(Date.now());
if (opt.log.respawns) {
logger.log('[' + worker.process.pid + '] worker (' + worker._rc_wid
opt.logger.info('[' + worker.process.pid + '] worker (' + worker._rc_wid
+ ':' + worker.id + ') must be replaced, respawning in', interval);
}

Expand All @@ -114,11 +108,9 @@ var ReloadCluster = (file, opt) => {
}, interval);

respawnerTimers.add(respawnerTimer);
}
} catch (e) {//ignore error
} catch (e) {
console.warn(e);
}

}

/**
Expand Down Expand Up @@ -351,7 +343,7 @@ function RespawnIntervalManager(opt) {
var respawnInterval = opt.minRespawnInterval || 1; // default to 1 sec
var lastSpawn = Date.now();

function getIntervalForNextSpawn(now) {
this.getIntervalForNextSpawn = function (now) {
var nextSpawn = Math.max(now, lastSpawn + respawnInterval * 1000),
intervalForNextSpawn = nextSpawn - now;
lastSpawn = nextSpawn;
Expand Down

0 comments on commit eab32fd

Please sign in to comment.