From 7184708a2008b7195bbade884ce05343378138c7 Mon Sep 17 00:00:00 2001 From: blam Date: Fri, 22 Sep 2023 15:15:31 +0200 Subject: [PATCH] chore: tinker around a little bit Signed-off-by: blam --- packages/backend-tasks/src/tasks/TaskWorker.ts | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/packages/backend-tasks/src/tasks/TaskWorker.ts b/packages/backend-tasks/src/tasks/TaskWorker.ts index b5c4162f68..c83bccb197 100644 --- a/packages/backend-tasks/src/tasks/TaskWorker.ts +++ b/packages/backend-tasks/src/tasks/TaskWorker.ts @@ -71,8 +71,6 @@ export class TaskWorker { let attemptNum = 1; (async () => { for (;;) { - const endDuration = this.duration.startTimer(); - try { if (settings.initialDelayDuration) { await sleep( @@ -82,7 +80,12 @@ export class TaskWorker { } while (!options?.signal?.aborted) { + const endDuration = this.duration.startTimer(); const runResult = await this.runOnce(options?.signal); + endDuration({ task_id: this.taskId, result: 'completed' }); + + this.counter.inc({ task_id: this.taskId, result: 'completed' }, 1); + if (runResult.result === 'abort') { break; } @@ -91,8 +94,7 @@ export class TaskWorker { } this.logger.info(`Task worker finished: ${this.taskId}`); - this.counter.inc({ task_id: this.taskId, result: 'completed' }, 1); - endDuration({ task_id: this.taskId, result: 'completed' }); + attemptNum = 0; break; } catch (e) { @@ -101,7 +103,6 @@ export class TaskWorker { `Task worker failed unexpectedly, attempt number ${attemptNum}, ${e}`, ); this.counter.inc({ task_id: this.taskId, result: 'failed' }, 1); - endDuration({ task_id: this.taskId, result: 'failed' }); await sleep(Duration.fromObject({ seconds: 1 })); } }