Skip to content

Commit

Permalink
if all workers disconnect, slicer will terminate resolves #253
Browse files Browse the repository at this point in the history
  • Loading branch information
jsnoble committed Sep 7, 2017
1 parent 9da9f4e commit 8d7fa28
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions lib/cluster/slicer.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ module.exports = function(context) {
var inRecoveryMode = false;
var hasRecovered = false;
var workerFound = false;
var isShuttingDown = false;

//temporary fix
var retryState = {};
Expand Down Expand Up @@ -213,6 +214,15 @@ module.exports = function(context) {
logger.warn(`Worker: ${worker_id} has disconnected`);
events.emit('network:disconnect', worker_id);
workerQueue.remove(worker_id);
//only call if workers have connected before, and there are none left
if (!isShuttingDown && workerFound && messaging.getClientCounts() === 0) {
//TODO this needs a refactor for when slicer controls ex state
messaging.send({
message: 'slicer:error:terminal',
error: `all workers from slicer #${ex_id} have disconnected`,
ex_id: ex_id
})
}
});

events.on('slicer:slice:recursion', function() {
Expand Down Expand Up @@ -464,7 +474,7 @@ module.exports = function(context) {

function slicerShutdown(msg) {
logger.info(`slicer for job: ${ex_id} has received a shutdown notice`);

isShuttingDown = true;
engineCanRun = false;
clearInterval(engine);
clearInterval(analyticsTimer);
Expand Down Expand Up @@ -601,7 +611,7 @@ module.exports = function(context) {
}

function checkJobState(jobConfig) {
var query = 'ex_id:' + jobConfig.ex_id + ' AND state:error';
var query = `ex_id:${jobConfig.ex_id} AND (state:error OR state:start)`;
return state_store.count(query, 0)
}

Expand Down

0 comments on commit 8d7fa28

Please sign in to comment.