From 58baffd328c308bbffed882ebdc8bb68b8198b26 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Thu, 24 Aug 2023 00:46:44 +0200 Subject: [PATCH] refactor: cleanup tasks redistribution on error code 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 | 36 ++++++++++++++---------------------- 1 file changed, 14 insertions(+), 22 deletions(-) diff --git a/src/pools/abstract-pool.ts b/src/pools/abstract-pool.ts index c6712d19..7b0d541d 100644 --- a/src/pools/abstract-pool.ts +++ b/src/pools/abstract-pool.ts @@ -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 = { -- 2.34.1