clusterpost-execution
Version:
Download data from the data provider to the local disk. Submit tasks to the job manager. Check if the task has finished and upload the results back to the data provider
78 lines (73 loc) • 2.95 kB
JavaScript
var _ = require('underscore');
module.exports = function(doc, conf){
var executionmethods = require('./executionserver.methods')(conf);
var clusterengine = require("./" + conf.engine)(conf);
const allUpload = function(allupload){
return executionmethods.getDocument(doc._id)
.then(function(docupdated){
docupdated.jobstatus.uploadstatus = allupload;
var alluploadstatus = true;
for(var i = 0; i < allupload.length; i++){
if(!(allupload[i].ok || allupload[i].statusCode == 409)){
alluploadstatus = false;
}
}
if(alluploadstatus){
docupdated.jobstatus.status = "DONE";
}else{
docupdated.jobstatus.status = "FAIL";
}
docupdated.timestampend = new Date();
return executionmethods.uploadDocumentDataProvider(docupdated);
});
}
if(conf.engine == "engine_awsecs"){
if(doc){
return clusterengine.getJobStatus(doc)
.then(function(status){
if(status.status === 'FAIL'){
doc.jobstatus = _.extend(doc.jobstatus, status);
return executionmethods.uploadDocumentDataProvider(doc)
.then(function(){
return status;
});
}
return status;
})
}else{
return clusterengine.checkGPUNodes();
}
}else{
if(doc){
if(doc.jobstatus.status === "UPLOADING"){
return executionmethods.checkAllDocumentOutputs(doc)
.then(allUpload);
}else{
return clusterengine.getJobStatus(doc)
.then(function(status){
if(status.status === 'DONE' || status.status === 'EXIT'){
doc.jobstatus.status = "UPLOADING";
//Set the new status
return executionmethods.uploadDocumentDataProvider(doc)
.then(function(res){
//update revision
doc._rev = res.rev;
return doc;
})
.then(function(doc){
//upload all outputs
return executionmethods.setAllDocumentOutputs(doc)
})
.then(allUpload);
}else{
doc.jobstatus = _.extend(doc.jobstatus, status);
return executionmethods.uploadDocumentDataProvider(doc)
.then(function(){
return status;
});
}
});
}
}
}
}