Skip to content

Commit

Permalink
first round of starting slicer/worker on startup resolves #519
Browse files Browse the repository at this point in the history
  • Loading branch information
jsnoble committed Sep 11, 2017
1 parent acec5a8 commit f867e87
Showing 1 changed file with 45 additions and 1 deletion.
46 changes: 45 additions & 1 deletion lib/cluster/node_master.js
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ module.exports = function(context) {
});

function jobNeedsAssets(jobStr){
var job = JSON.parse(jobStr);
var job = typeof jobStr == 'string' ? JSON.parse(jobStr) : jobStr;
return job.assets && job.assets.length > 0
}

Expand Down Expand Up @@ -418,4 +418,48 @@ module.exports = function(context) {
logger.debug(`node ${context.sysconfig._nodeName} is creating the moderator`);
context.foundation.startWorkers(1, {assignment: 'moderator', node_id: context.sysconfig._nodeName});
}

if(process.env.CLUSTER_MANAGER_TYPE === 'kubernetes'){
var worker_type = process.env.NODE_TYPE;
var jobStr = process.env.EX;
var ex;

try {
ex = JSON.parse(jobStr)
}
catch(err){
var errMsg = parseError(err);
logger.error(`error while loading EX from enviroment, error: ${errMsg}`);
//give it time to log before exiting
setTimeout(()=> process.exit(), 100)
}

var needAssets = jobNeedsAssets(ex);

var childContext = {
assignment: worker_type,
job: jobStr,
node_id: context.sysconfig._nodeName,
ex_id: ex.ex_id,
job_id: ex.job_id,
slicer_port: ex.slicer_port
};
//TODO need to set recover_execution somehow
//used to retry a job on startup after a stop command
if (ex.recover_execution) {
childContext.recover_execution = true;
}

context.foundation.startWorkers(1, childContext);

if (needAssets) {
logger.info(`node ${context.sysconfig._nodeName} is checking assets for job ${ex.ex_id}`);
context.foundation.startWorkers(1, {
assignment: 'assets_loader',
node_id: context.sysconfig._nodeName,
job: ex.job,
ex_id: ex.ex_id
});
}
}
};

0 comments on commit f867e87

Please sign in to comment.