Improve task progress values
0: not yet handled 1: queued 2: started 100: finished
This commit is contained in:
@@ -59,9 +59,13 @@ function postProcess(result) {
|
||||
assert.strictEqual(typeof result, 'object');
|
||||
|
||||
result.active = !!gTasks[result.id];
|
||||
|
||||
// we rely on 'percent' to determine success. maybe this can become a db field
|
||||
result.success = result.percent === 100 && !result.error;
|
||||
|
||||
// we rely on 'percent' to determine pending. maybe this can become a db field
|
||||
result.pending = result.percent === 1;
|
||||
|
||||
// the error in db will be empty if we didn't get a chance to handle task exit
|
||||
if (!result.active && result.percent !== 100 && !result.error) {
|
||||
result.error = { message: 'Cloudron crashed/stopped', code: exports.ECRASHED };
|
||||
@@ -127,7 +131,7 @@ function add(type, args, callback) {
|
||||
assert(Array.isArray(args));
|
||||
assert.strictEqual(typeof callback, 'function');
|
||||
|
||||
taskdb.add({ type: type, percent: 1, message: 'Queued', args: args }, function (error, taskId) {
|
||||
taskdb.add({ type: type, percent: 0, message: 'Queued', args: args }, function (error, taskId) {
|
||||
if (error) return callback(error);
|
||||
|
||||
callback(null, taskId);
|
||||
@@ -273,6 +277,6 @@ function getLogs(taskId, options, callback) {
|
||||
|
||||
// removes all fields that are strictly private and should never be returned by API calls
|
||||
function removePrivateFields(task) {
|
||||
var result = _.pick(task, 'id', 'type', 'percent', 'message', 'error', 'active', 'creationTime', 'result', 'ts', 'success');
|
||||
var result = _.pick(task, 'id', 'type', 'percent', 'message', 'error', 'active', 'pending', 'creationTime', 'result', 'ts', 'success');
|
||||
return result;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user