tasks: rework the startTask API

it is now async. change was required to reset the pending flag
This commit is contained in:
Girish Ramakrishnan
2025-06-17 18:54:12 +02:00
parent 4770b32287
commit d9c104613c
13 changed files with 178 additions and 202 deletions
+10 -7
View File
@@ -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;
}