From: Jérôme Benoit Date: Tue, 14 May 2024 11:48:23 +0000 (+0200) Subject: refactor: cleanup handleWorkerNodeIdleEvent() X-Git-Tag: v4.0.8~5 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=010f158c374ba75715130189cc1c53d8f6ca275f;p=poolifier.git refactor: cleanup handleWorkerNodeIdleEvent() Signed-off-by: Jérôme Benoit --- 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) {