From 71b2b6d8c0678320a3b6390c058f0d7338b10918 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Thu, 17 Aug 2023 01:03:49 +0200 Subject: [PATCH] fix: fix task function names property in worker-node MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- src/pools/worker-node.ts | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/pools/worker-node.ts b/src/pools/worker-node.ts index 923fe9b2..4349ed72 100644 --- a/src/pools/worker-node.ts +++ b/src/pools/worker-node.ts @@ -23,7 +23,6 @@ implements IWorkerNode { public readonly worker: Worker public readonly info: WorkerInfo public usage: WorkerUsage - public taskFunctions!: string[] private readonly tasksUsage: Map private readonly tasksQueue: Queue> @@ -89,12 +88,17 @@ implements IWorkerNode { /** @inheritdoc */ public getTaskWorkerUsage (name: string): WorkerUsage | undefined { + if (name === DEFAULT_TASK_NAME && !Array.isArray(this.info.taskFunctions)) { + throw new Error( + 'Cannot get task worker usage for default task function name when task function names list is not yet defined' + ) + } if ( name === DEFAULT_TASK_NAME && - Array.isArray(this.taskFunctions) && - this.taskFunctions.length > 1 + Array.isArray(this.info.taskFunctions) && + this.info.taskFunctions.length > 1 ) { - name = this.taskFunctions[1] + name = this.info.taskFunctions[1] } if (!this.tasksUsage.has(name)) { this.tasksUsage.set(name, this.initTaskWorkerUsage(name)) -- 2.34.1