Improve task progress values
0: not yet handled 1: queued 2: started 100: finished
This commit is contained in:
@@ -72,24 +72,32 @@ async.series([
|
||||
tasks.get(taskId, function (error, task) {
|
||||
if (error) return process.exit(50);
|
||||
|
||||
const progressCallback = (progress, cb) => tasks.update(taskId, progress, cb || NOOP_CALLBACK);
|
||||
const resultCallback = (error, result) => {
|
||||
// Error object has properties with enumerable: false (https://mattcbaker.com/posts/stringify-javascript-error/)
|
||||
const progress = {
|
||||
result: result || null,
|
||||
error: error ? JSON.parse(JSON.stringify(error, Object.getOwnPropertyNames(error))) : null
|
||||
tasks.update(taskId, { percent: 2, error: null }, function (error) {
|
||||
if (error) {
|
||||
console.error(error);
|
||||
return process.exit(50);
|
||||
}
|
||||
|
||||
const progressCallback = (progress, cb) => tasks.update(taskId, progress, cb || NOOP_CALLBACK);
|
||||
const resultCallback = (error, result) => {
|
||||
// Error object has properties with enumerable: false (https://mattcbaker.com/posts/stringify-javascript-error/)
|
||||
const progress = {
|
||||
result: result || null,
|
||||
error: error ? JSON.parse(JSON.stringify(error, Object.getOwnPropertyNames(error))) : null
|
||||
};
|
||||
|
||||
debug(`Task took ${(new Date() - startTime)/1000} seconds`);
|
||||
|
||||
tasks.setCompleted(taskId, progress, () => process.exit(error ? 50 : 0));
|
||||
};
|
||||
|
||||
debug(`Task took ${(new Date() - startTime)/1000} seconds`);
|
||||
try {
|
||||
TASKS[task.type].apply(null, task.args.concat(progressCallback).concat(resultCallback));
|
||||
} catch (error) {
|
||||
debug('Uncaught exception in task', error);
|
||||
process.exit(1); // do not call setCompleted() intentionally. the task code must be resilient enough to handle it
|
||||
}
|
||||
});
|
||||
|
||||
tasks.setCompleted(taskId, progress, () => process.exit(error ? 50 : 0));
|
||||
};
|
||||
|
||||
try {
|
||||
TASKS[task.type].apply(null, task.args.concat(progressCallback).concat(resultCallback));
|
||||
} catch (error) {
|
||||
debug('Uncaught exception in task', error);
|
||||
process.exit(1); // do not call setCompleted() intentionally. the task code must be resilient enough to handle it
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user