diff --git a/src/apptaskmanager.js b/src/apptaskmanager.js index 6952ead55..673653adc 100644 --- a/src/apptaskmanager.js +++ b/src/apptaskmanager.js @@ -83,6 +83,7 @@ function scheduleTask(appId, taskId, options, onFinished) { return; } + // percent 1 is relies on the tasks "active" flag to indicate task is queued but not started yet tasks.update(taskId, { percent: 1, message: gStarted ? 'Queued' : 'Waiting for platform to initialize' }); gPendingTasks.push({ appId, taskId, options, onFinished }); diff --git a/src/tasks.js b/src/tasks.js index 773e3698d..5cacf61b9 100644 --- a/src/tasks.js +++ b/src/tasks.js @@ -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 };