refactor: cleanup tasks redistribution on error code
authorJérôme Benoit <jerome.benoit@piment-noir.org>
Wed, 23 Aug 2023 22:46:44 +0000 (00:46 +0200)
committerJérôme Benoit <jerome.benoit@piment-noir.org>
Wed, 23 Aug 2023 22:46:44 +0000 (00:46 +0200)
Signed-off-by: Jérôme Benoit <jerome.benoit@piment-noir.org>
src/pools/abstract-pool.ts

index c6712d198bc28a9d77c08ae817e5c96c3b9227c6..7b0d541d8bcafaaaab1150fa01067c66acea30c2 100644 (file)
@@ -1194,29 +1194,21 @@ export abstract class AbstractPool<
       let minQueuedTasks = Infinity
       let executeTask = false
       for (const [workerNodeId, workerNode] of this.workerNodes.entries()) {
-        if (
-          workerNode.info.ready &&
-          workerNodeId !== workerNodeKey &&
-          workerNode.usage.tasks.executing <
+        if (workerNode.info.ready && workerNodeId !== workerNodeKey) {
+          if (
+            workerNode.usage.tasks.executing <
             (this.opts.tasksQueueOptions?.concurrency as number)
-        ) {
-          executeTask = true
-        }
-        if (
-          workerNode.info.ready &&
-          workerNodeId !== workerNodeKey &&
-          workerNode.usage.tasks.queued === 0
-        ) {
-          destinationWorkerNodeKey = workerNodeId
-          break
-        }
-        if (
-          workerNode.info.ready &&
-          workerNodeId !== workerNodeKey &&
-          workerNode.usage.tasks.queued < minQueuedTasks
-        ) {
-          minQueuedTasks = workerNode.usage.tasks.queued
-          destinationWorkerNodeKey = workerNodeId
+          ) {
+            executeTask = true
+          }
+          if (workerNode.usage.tasks.queued === 0) {
+            destinationWorkerNodeKey = workerNodeId
+            break
+          }
+          if (workerNode.usage.tasks.queued < minQueuedTasks) {
+            minQueuedTasks = workerNode.usage.tasks.queued
+            destinationWorkerNodeKey = workerNodeId
+          }
         }
       }
       const task = {