Skip to content

Commit

Permalink
Merge pull request #162 from pierotofy/corrupt
Browse files Browse the repository at this point in the history
Set post processing options on restart
  • Loading branch information
pierotofy committed Jun 22, 2021
2 parents bb8b7bd + d25f72a commit 48f61d9
Showing 1 changed file with 55 additions and 44 deletions.
99 changes: 55 additions & 44 deletions libs/Task.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,46 +63,7 @@ module.exports = class Task{
}

initialize(done, additionalSteps = []){
async.series(additionalSteps.concat([
// Handle post-processing options logic
cb => {
// If we need to post process results
// if pc-ept is supported (build entwine point cloud)
// we automatically add the pc-ept option to the task options by default
if (this.skipPostProcessing) cb();
else{
odmInfo.supportsOption("pc-ept", (err, supported) => {
if (err){
console.warn(`Cannot check for supported option pc-ept: ${err}`);
}else if (supported){
if (!this.options.find(opt => opt.name === "pc-ept")){
this.options.push({ name: 'pc-ept', value: true });
}
}
cb();
});
}
},

cb => {
// If we need to post process results
// if cog is supported (build cloud optimized geotiffs)
// we automatically add the cog option to the task options by default
if (this.skipPostProcessing) cb();
else{
odmInfo.supportsOption("cog", (err, supported) => {
if (err){
console.warn(`Cannot check for supported option cog: ${err}`);
}else if (supported){
if (!this.options.find(opt => opt.name === "cog")){
this.options.push({ name: 'cog', value: true });
}
}
cb();
});
}
},

async.series(additionalSteps.concat(this.setPostProcessingOptsSteps(), [
// Read images info
cb => {
fs.readdir(this.getImagesFolderPath(), (err, files) => {
Expand Down Expand Up @@ -150,6 +111,48 @@ module.exports = class Task{
});
}

setPostProcessingOptsSteps(){
return [
cb => {
// If we need to post process results
// if pc-ept is supported (build entwine point cloud)
// we automatically add the pc-ept option to the task options by default
if (this.skipPostProcessing) cb();
else{
odmInfo.supportsOption("pc-ept", (err, supported) => {
if (err){
console.warn(`Cannot check for supported option pc-ept: ${err}`);
}else if (supported){
if (!this.options.find(opt => opt.name === "pc-ept")){
this.options.push({ name: 'pc-ept', value: true });
}
}
cb();
});
}
},

cb => {
// If we need to post process results
// if cog is supported (build cloud optimized geotiffs)
// we automatically add the cog option to the task options by default
if (this.skipPostProcessing) cb();
else{
odmInfo.supportsOption("cog", (err, supported) => {
if (err){
console.warn(`Cannot check for supported option cog: ${err}`);
}else if (supported){
if (!this.options.find(opt => opt.name === "cog")){
this.options.push({ name: 'cog', value: true });
}
}
cb();
});
}
}
];
}

static CreateFromSerialized(taskJson, done){
const task = new Task(taskJson.uuid,
taskJson.name,
Expand Down Expand Up @@ -617,17 +620,25 @@ module.exports = class Task{
restart(options, cb){
if (!this.initialized && this.status.code === statusCodes.CANCELED){
this.setStatus(statusCodes.RUNNING);
if (options !== undefined) this.options = options;
cb(null);
if (options !== undefined){
this.options = options;
async.series(this.setPostProcessingOptsSteps(), cb);
}else{
cb();
}
}else if ([statusCodes.CANCELED, statusCodes.FAILED, statusCodes.COMPLETED].indexOf(this.status.code) !== -1){
this.setStatus(statusCodes.QUEUED);
this.dateCreated = new Date().getTime();
this.dateStarted = 0;
this.output = [];
this.progress = 0;
this.stopTrackingProcessingTime(true);
if (options !== undefined) this.options = options;
cb(null);
if (options !== undefined){
this.options = options;
async.series(this.setPostProcessingOptsSteps(), cb);
}else{
cb();
}
}else{
cb(new Error("Task cannot be restarted"));
}
Expand Down

0 comments on commit 48f61d9

Please sign in to comment.