kopia lustrzana https://github.com/OpenDroneMap/NodeODM
Refactoring, remove images.json from download API, updated hook callback with images database
rodzic
354bb9c591
commit
5dd99884e7
|
@ -3,7 +3,7 @@
|
||||||
|
|
||||||
[[_overview]]
|
[[_overview]]
|
||||||
== Overview
|
== Overview
|
||||||
REST API to access OpenDroneMap
|
REST API to access ODM
|
||||||
|
|
||||||
|
|
||||||
=== Version information
|
=== Version information
|
||||||
|
@ -281,7 +281,7 @@ Retrieves an asset (the output of OpenDroneMap's processing) associated with a t
|
||||||
|===
|
|===
|
||||||
|Type|Name|Description|Schema|Default
|
|Type|Name|Description|Schema|Default
|
||||||
|*Path*|*asset* +
|
|*Path*|*asset* +
|
||||||
_required_|Type of asset to download. Use "all.zip" for zip file containing all assets.|enum (all.zip, orthophoto.tif, images.json)|
|
_required_|Type of asset to download. Use "all.zip" for zip file containing all assets.|enum (all.zip, orthophoto.tif)|
|
||||||
|*Path*|*uuid* +
|
|*Path*|*uuid* +
|
||||||
_required_|UUID of the task|string|
|
_required_|UUID of the task|string|
|
||||||
|*Query*|*token* +
|
|*Query*|*token* +
|
||||||
|
|
File diff suppressed because one or more lines are too long
1
index.js
1
index.js
|
@ -419,7 +419,6 @@ app.get('/task/:uuid/output', authCheck, getTaskFromUuid, (req, res) => {
|
||||||
* enum:
|
* enum:
|
||||||
* - all.zip
|
* - all.zip
|
||||||
* - orthophoto.tif
|
* - orthophoto.tif
|
||||||
* - images.json
|
|
||||||
* -
|
* -
|
||||||
* name: token
|
* name: token
|
||||||
* in: query
|
* in: query
|
||||||
|
|
68
libs/Task.js
68
libs/Task.js
|
@ -31,6 +31,7 @@ const archiver = require('archiver');
|
||||||
const Directories = require('./Directories');
|
const Directories = require('./Directories');
|
||||||
const kill = require('tree-kill');
|
const kill = require('tree-kill');
|
||||||
const S3 = require('./S3');
|
const S3 = require('./S3');
|
||||||
|
const request = require('request');
|
||||||
|
|
||||||
const statusCodes = require('./statusCodes');
|
const statusCodes = require('./statusCodes');
|
||||||
|
|
||||||
|
@ -132,12 +133,6 @@ module.exports = class Task{
|
||||||
}else{
|
}else{
|
||||||
filename = path.join('odm_orthophoto', `odm_${filename}`);
|
filename = path.join('odm_orthophoto', `odm_${filename}`);
|
||||||
}
|
}
|
||||||
}else if (filename == 'images.json'){
|
|
||||||
if (config.test){
|
|
||||||
filename = path.join('..', '..', 'processing_results', 'images.json');
|
|
||||||
}else{
|
|
||||||
// OK, do nothing
|
|
||||||
}
|
|
||||||
}else{
|
}else{
|
||||||
return false; // Invalid
|
return false; // Invalid
|
||||||
}
|
}
|
||||||
|
@ -447,7 +442,66 @@ module.exports = class Task{
|
||||||
// Optionally starting from a certain line number
|
// Optionally starting from a certain line number
|
||||||
getOutput(startFromLine = 0){
|
getOutput(startFromLine = 0){
|
||||||
return this.output.slice(startFromLine, this.output.length);
|
return this.output.slice(startFromLine, this.output.length);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Reads the contents of the tasks's
|
||||||
|
// images.json and returns its JSON representation
|
||||||
|
readImagesDatabase(callback){
|
||||||
|
const imagesDbPath = !config.test ?
|
||||||
|
path.join(this.getProjectFolderPath(), 'images.json') :
|
||||||
|
path.join('tests', 'processing_results', 'images.json');
|
||||||
|
|
||||||
|
fs.readFile(imagesDbPath, 'utf8', (err, data) => {
|
||||||
|
if (err) callback(err);
|
||||||
|
else{
|
||||||
|
try{
|
||||||
|
const json = JSON.parse(data);
|
||||||
|
callback(null, json);
|
||||||
|
}catch(e){
|
||||||
|
callback(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
callWebhooks(){
|
||||||
|
// Hooks can be passed via command line
|
||||||
|
// or for each individual task
|
||||||
|
const hooks = [this.webhook, config.webhook];
|
||||||
|
|
||||||
|
this.readImagesDatabase((err, images) => {
|
||||||
|
if (err) logger.warn(err); // Continue with callback
|
||||||
|
if (!images) images = [];
|
||||||
|
|
||||||
|
hooks.forEach(hook => {
|
||||||
|
if (hook && hook.length > 3){
|
||||||
|
const notifyCallback = (attempt) => {
|
||||||
|
if (attempt > 5){
|
||||||
|
logger.warn(`Webhook invokation failed, will not retry: ${hook}`);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
request.post(hook, {
|
||||||
|
json: {
|
||||||
|
task: this.getInfo(),
|
||||||
|
images: images
|
||||||
|
}
|
||||||
|
},
|
||||||
|
(error, response) => {
|
||||||
|
if (error || response.statusCode != 200){
|
||||||
|
logger.warn(`Webhook invokation failed, will retry in a bit: ${hook}`);
|
||||||
|
setTimeout(() => {
|
||||||
|
notifyCallback(attempt + 1);
|
||||||
|
}, attempt * 5000);
|
||||||
|
}else{
|
||||||
|
logger.debug(`Webhook invoked: ${hook}`);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
notifyCallback(0);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
// Returns the data necessary to serialize this
|
// Returns the data necessary to serialize this
|
||||||
// task to restore it later.
|
// task to restore it later.
|
||||||
|
|
|
@ -16,18 +16,17 @@ You should have received a copy of the GNU General Public License
|
||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
"use strict";
|
"use strict";
|
||||||
let assert = require('assert');
|
const assert = require('assert');
|
||||||
let config = require('../config');
|
const config = require('../config');
|
||||||
let rmdir = require('rimraf');
|
const rmdir = require('rimraf');
|
||||||
let fs = require('fs');
|
const fs = require('fs');
|
||||||
let path = require('path');
|
const path = require('path');
|
||||||
let logger = require('./logger');
|
const logger = require('./logger');
|
||||||
let Task = require('./Task');
|
const Task = require('./Task');
|
||||||
let statusCodes = require('./statusCodes');
|
const statusCodes = require('./statusCodes');
|
||||||
let async = require('async');
|
const async = require('async');
|
||||||
let schedule = require('node-schedule');
|
const schedule = require('node-schedule');
|
||||||
let Directories = require('./Directories');
|
const Directories = require('./Directories');
|
||||||
let request = require('request');
|
|
||||||
|
|
||||||
const TASKS_DUMP_FILE = path.join(Directories.data, "tasks.json");
|
const TASKS_DUMP_FILE = path.join(Directories.data, "tasks.json");
|
||||||
const CLEANUP_TASKS_IF_OLDER_THAN = 1000 * 60 * config.cleanupTasksAfter; // minutes
|
const CLEANUP_TASKS_IF_OLDER_THAN = 1000 * 60 * config.cleanupTasksAfter; // minutes
|
||||||
|
@ -150,34 +149,8 @@ module.exports = class TaskManager{
|
||||||
if (task){
|
if (task){
|
||||||
this.addToRunningQueue(task);
|
this.addToRunningQueue(task);
|
||||||
task.start(() => {
|
task.start(() => {
|
||||||
// Hooks can be passed via command line
|
|
||||||
// or for each individual task
|
|
||||||
const hooks = [task.webhook, config.webhook];
|
|
||||||
|
|
||||||
hooks.forEach(hook => {
|
task.callWebhooks();
|
||||||
if (hook && hook.length > 3){
|
|
||||||
const notifyCallback = (attempt) => {
|
|
||||||
if (attempt > 5){
|
|
||||||
logger.warn(`Callback failed, will not retry: ${hook}`);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
request.post(hook, {
|
|
||||||
json: task.getInfo()
|
|
||||||
},
|
|
||||||
(error, response) => {
|
|
||||||
if (error || response.statusCode != 200){
|
|
||||||
logger.warn(`Callback failed, will retry in a bit: ${hook}`);
|
|
||||||
setTimeout(() => {
|
|
||||||
notifyCallback(attempt + 1);
|
|
||||||
}, attempt * 5000);
|
|
||||||
}else{
|
|
||||||
logger.debug(`Callback invoked: ${hook}`);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
};
|
|
||||||
notifyCallback(0);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
this.removeFromRunningQueue(task);
|
this.removeFromRunningQueue(task);
|
||||||
this.processNextTask();
|
this.processNextTask();
|
||||||
|
|
Ładowanie…
Reference in New Issue