From: Jérôme Benoit Date: Sun, 9 Apr 2023 20:56:28 +0000 (+0200) Subject: fix: ensure not more than one task is executed on a worker with tasks X-Git-Tag: v2.4.6~11 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=26a929d7a30913e453f44cb63409861e72f5aac3;p=poolifier.git fix: ensure not more than one task is executed on a worker with tasks queuing enabled Signed-off-by: Jérôme Benoit --- diff --git a/src/pools/abstract-pool.ts b/src/pools/abstract-pool.ts index 41ce6aa0..a8104e9e 100644 --- a/src/pools/abstract-pool.ts +++ b/src/pools/abstract-pool.ts @@ -236,17 +236,14 @@ export abstract class AbstractPool< id: crypto.randomUUID() } const res = this.internalExecute(workerNodeKey, workerNode, submittedTask) - let currentTask: Task = submittedTask if ( this.opts.enableTasksQueue === true && - (this.busy || this.tasksQueueSize(workerNodeKey) > 0) + (this.busy || this.workerNodes[workerNodeKey].tasksUsage.running > 0) ) { - currentTask = this.enqueueDequeueTask( - workerNodeKey, - submittedTask - ) as Task + this.enqueueTask(workerNodeKey, submittedTask) + } else { + this.sendToWorker(workerNode.worker, submittedTask) } - this.sendToWorker(workerNode.worker, currentTask) this.checkAndEmitEvents() // eslint-disable-next-line @typescript-eslint/return-await return res @@ -558,14 +555,6 @@ export abstract class AbstractPool< this.workerChoiceStrategyContext.remove(workerNodeKey) } - private enqueueDequeueTask ( - workerNodeKey: number, - task: Task - ): Task | undefined { - this.enqueueTask(workerNodeKey, task) - return this.dequeueTask(workerNodeKey) - } - private enqueueTask (workerNodeKey: number, task: Task): void { this.workerNodes[workerNodeKey].tasksQueue.push(task) }