tasks: fix active status

This commit is contained in:
Girish Ramakrishnan
2024-12-12 19:07:03 +01:00
parent 3be77fc634
commit d456f91921
2 changed files with 8 additions and 4 deletions

View File

@@ -84,14 +84,17 @@ function postProcess(task) {
function updateStatus(result) {
assert.strictEqual(typeof result, 'object');
result.active = !!gTasks[result.id];
// running means actively running
// pending means not actively running
// active mean task is 'done' or not. at this point, clients can stop polling this task.
// the apptaskmanager sets percent=1 when queued. just a hack to figure non-started but scheduled tasks
result.running = !!gTasks[result.id];
result.active = result.running || result.percent === 1;
result.pending = !gTasks[result.id] && result.active;
// 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: 'Task was stopped because the server was restarted or crashed', code: exports.ECRASHED };