tasks: rework the startTask API
it is now async. change was required to reset the pending flag
This commit is contained in:
+23
-20
@@ -255,16 +255,20 @@ async function startBackupTask(auditSource) {
|
||||
|
||||
await eventlog.add(eventlog.ACTION_BACKUP_START, auditSource, { taskId });
|
||||
|
||||
tasks.startTask(taskId, { timeout: 24 * 60 * 60 * 1000 /* 24 hours */, nice: 15, memoryLimit, oomScoreAdjust: -999 }, async function (error, backupId) {
|
||||
await locks.release(locks.TYPE_BACKUP_TASK);
|
||||
await locks.releaseByTaskId(taskId);
|
||||
|
||||
const errorMessage = error ? error.message : '';
|
||||
const timedOut = error ? error.code === tasks.ETIMEOUT : false;
|
||||
|
||||
const backup = backupId ? await get(backupId) : null;
|
||||
await safe(eventlog.add(eventlog.ACTION_BACKUP_FINISH, auditSource, { taskId, errorMessage, timedOut, backupId, remotePath: backup?.remotePath }), { debug });
|
||||
});
|
||||
// background
|
||||
tasks.startTask(taskId, { timeout: 24 * 60 * 60 * 1000 /* 24 hours */, nice: 15, memoryLimit, oomScoreAdjust: -999 })
|
||||
.then(async (backupId) => {
|
||||
const backup = await get(backupId);
|
||||
await eventlog.add(eventlog.ACTION_BACKUP_FINISH, auditSource, { taskId, backupId, remotePath: backup.remotePath });
|
||||
})
|
||||
.catch(async (error) => {
|
||||
const timedOut = error.code === tasks.ETIMEOUT;
|
||||
await safe(eventlog.add(eventlog.ACTION_BACKUP_FINISH, auditSource, { taskId, errorMessage: error.message, timedOut }));
|
||||
})
|
||||
.finally(async () => {
|
||||
await locks.release(locks.TYPE_BACKUP_TASK);
|
||||
await locks.releaseByTaskId(taskId);
|
||||
});
|
||||
|
||||
return taskId;
|
||||
}
|
||||
@@ -326,16 +330,15 @@ async function startCleanupTask(auditSource) {
|
||||
|
||||
const taskId = await tasks.add(tasks.TASK_CLEAN_BACKUPS, []);
|
||||
|
||||
tasks.startTask(taskId, {}, async (error, result) => { // result is { removedBoxBackupPaths, removedAppBackupPaths, removedMailBackupPaths, missingBackupPaths }
|
||||
await safe(eventlog.add(eventlog.ACTION_BACKUP_CLEANUP_FINISH, auditSource, {
|
||||
taskId,
|
||||
errorMessage: error ? error.message : null,
|
||||
removedBoxBackupPaths: result ? result.removedBoxBackupPaths : [],
|
||||
removedMailBackupPaths: result ? result.removedMailBackupPaths : [],
|
||||
removedAppBackupPaths: result ? result.removedAppBackupPaths : [],
|
||||
missingBackupPaths: result ? result.missingBackupPaths : []
|
||||
}), { debug });
|
||||
});
|
||||
// background
|
||||
tasks.startTask(taskId, {})
|
||||
.then(async (result) => { // { removedBoxBackupPaths, removedAppBackupPaths, removedMailBackupPaths, missingBackupPaths }
|
||||
await eventlog.add(eventlog.ACTION_BACKUP_CLEANUP_FINISH, auditSource, { taskId, errorMessage: null, ...result });
|
||||
})
|
||||
.catch(async (error) => {
|
||||
await eventlog.add(eventlog.ACTION_BACKUP_CLEANUP_FINISH, auditSource, { taskId, errorMessage: error.message });
|
||||
|
||||
});
|
||||
|
||||
return taskId;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user