refactor: cleanup handleWorkerNodeIdleEvent()
authorJérôme Benoit <jerome.benoit@piment-noir.org>
Tue, 14 May 2024 11:48:23 +0000 (13:48 +0200)
committerJérôme Benoit <jerome.benoit@piment-noir.org>
Tue, 14 May 2024 11:48:23 +0000 (13:48 +0200)
Signed-off-by: Jérôme Benoit <jerome.benoit@piment-noir.org>
src/pools/abstract-pool.ts

index 52bd73becbf5000cef602490de9a742019036cde..8a264c1944f713be2fef1782c2e47d201711b397 100644 (file)
@@ -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) {