tasks: rework the startTask API
it is now async. change was required to reset the pending flag
This commit is contained in:
+10
-7
@@ -216,15 +216,18 @@ async function updateToLatest(options, auditSource) {
|
||||
const taskId = await tasks.add(tasks.TASK_UPDATE, [ boxUpdateInfo, options ]);
|
||||
await eventlog.add(eventlog.ACTION_UPDATE, auditSource, { taskId, boxUpdateInfo });
|
||||
|
||||
tasks.startTask(taskId, { timeout: 20 * 60 * 60 * 1000 /* 20 hours */, nice: 15, memoryLimit }, async (error) => {
|
||||
await locks.release(locks.TYPE_UPDATE_TASK);
|
||||
await locks.releaseByTaskId(taskId);
|
||||
// background
|
||||
tasks.startTask(taskId, { timeout: 20 * 60 * 60 * 1000 /* 20 hours */, nice: 15, memoryLimit })
|
||||
.then(() => debug('updateToLatest: internal error. impossible code path'))
|
||||
.catch(async (error) => {
|
||||
debug('Update failed with error. %o', error);
|
||||
|
||||
debug('Update failed with error. %o', error);
|
||||
await locks.release(locks.TYPE_UPDATE_TASK);
|
||||
await locks.releaseByTaskId(taskId);
|
||||
|
||||
const timedOut = error.code === tasks.ETIMEOUT;
|
||||
await safe(eventlog.add(eventlog.ACTION_UPDATE_FINISH, auditSource, { taskId, errorMessage: error.message, timedOut }));
|
||||
});
|
||||
const timedOut = error.code === tasks.ETIMEOUT;
|
||||
await eventlog.add(eventlog.ACTION_UPDATE_FINISH, auditSource, { taskId, errorMessage: error.message, timedOut });
|
||||
});
|
||||
|
||||
return taskId;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user