fix: ensure not more than one task is executed on a worker with tasks
authorJérôme Benoit <jerome.benoit@sap.com>
Sun, 9 Apr 2023 20:56:28 +0000 (22:56 +0200)
committerJérôme Benoit <jerome.benoit@sap.com>
Sun, 9 Apr 2023 20:56:28 +0000 (22:56 +0200)
queuing enabled

Signed-off-by: Jérôme Benoit <jerome.benoit@sap.com>
src/pools/abstract-pool.ts

index 41ce6aa019a5269a0a47e338934c093aa2a3ee6d..a8104e9e26bdb31dd7d0374794538eafd9acb116 100644 (file)
@@ -236,17 +236,14 @@ export abstract class AbstractPool<
       id: crypto.randomUUID()
     }
     const res = this.internalExecute(workerNodeKey, workerNode, submittedTask)
-    let currentTask: Task<Data> = 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<Data>
+      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<Data>
-  ): Task<Data> | undefined {
-    this.enqueueTask(workerNodeKey, task)
-    return this.dequeueTask(workerNodeKey)
-  }
-
   private enqueueTask (workerNodeKey: number, task: Task<Data>): void {
     this.workerNodes[workerNodeKey].tasksQueue.push(task)
   }