From 010f158c374ba75715130189cc1c53d8f6ca275f Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Tue, 14 May 2024 13:48:23 +0200 Subject: [PATCH] refactor: cleanup handleWorkerNodeIdleEvent() MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- src/pools/abstract-pool.ts | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/pools/abstract-pool.ts b/src/pools/abstract-pool.ts index 52bd73be..8a264c19 100644 --- a/src/pools/abstract-pool.ts +++ b/src/pools/abstract-pool.ts @@ -1807,12 +1807,17 @@ export abstract class AbstractPool< ) } const workerInfo = this.getWorkerInfo(workerNodeKey) + if (workerInfo == null) { + throw new Error( + `Worker node with key '${workerNodeKey}' not found in pool` + ) + } if ( this.cannotStealTask() || (this.info.stealingWorkerNodes ?? 0) > Math.floor(this.workerNodes.length / 2) ) { - if (workerInfo != null && previousStolenTask != null) { + if (previousStolenTask != null) { workerInfo.stealing = false this.resetTaskSequentiallyStolenStatisticsWorkerUsage( workerNodeKey, @@ -1824,7 +1829,6 @@ export abstract class AbstractPool< } const workerNodeTasksUsage = this.workerNodes[workerNodeKey].usage.tasks if ( - workerInfo != null && previousStolenTask != null && (workerNodeTasksUsage.executing > 0 || this.tasksQueueSize(workerNodeKey) > 0) @@ -1837,11 +1841,6 @@ export abstract class AbstractPool< ) return } - if (workerInfo == null) { - throw new Error( - `Worker node with key '${workerNodeKey}' not found in pool` - ) - } workerInfo.stealing = true const stolenTask = this.workerNodeStealTask(workerNodeKey) if (stolenTask != null) { -- 2.34.1