Fix tasks test

This commit is contained in:
Girish Ramakrishnan
2025-07-18 20:55:46 +02:00
parent 3da1bae826
commit 4f608bdc5f
3 changed files with 14 additions and 12 deletions

View File

@@ -34,10 +34,11 @@ const TASKS = { // indexed by task type
syncDnsRecords: dns.syncDnsRecords,
syncDyndns: dyndns.sync,
_identity: async (arg, progressCallback) => { progressCallback({ percent: 20 }); return arg; },
_error: async (arg, progressCallback) => { progressCallback({ percent: 20 }); throw new Error(`Failed for arg: ${arg}`); },
_crash: (arg) => { throw new Error(`Crashing for arg: ${arg}`); }, // the test looks for this debug string in the log file
_sleep: async (arg) => await timers.setTimeout(parseInt(arg, 10))
// testing
identity: async (arg, progressCallback) => { progressCallback({ percent: 20 }); return arg; },
error: async (arg, progressCallback) => { progressCallback({ percent: 20 }); throw new Error(`Failed for arg: ${arg}`); },
crash: (arg) => { throw new Error(`Crashing for arg: ${arg}`); }, // the test looks for this debug string in the log file
sleep: async (arg) => await timers.setTimeout(parseInt(arg, 10))
};
if (process.argv.length !== 4) {
@@ -117,8 +118,9 @@ async function main() {
await safe(tasks.update(taskId, progress), { debug });
}
debug(`Running task of type ${task.type}`);
const [runError, result] = await safe(TASKS[task.type.replace(/_.*/,'')].apply(null, task.args.concat(progressCallback)));
const taskName = task.type.replace(/_.*/,'');
debug(`Running task of type ${taskName}`);
const [runError, result] = await safe(TASKS[taskName].apply(null, task.args.concat(progressCallback)));
const progress = {
result: result || null,
error: runError ? toTaskError(runError) : null,