refactor: cleanup worker node back pressure checks
authorJérôme Benoit <jerome.benoit@piment-noir.org>
Tue, 27 Aug 2024 17:15:03 +0000 (19:15 +0200)
committerJérôme Benoit <jerome.benoit@piment-noir.org>
Tue, 27 Aug 2024 17:15:03 +0000 (19:15 +0200)
Signed-off-by: Jérôme Benoit <jerome.benoit@piment-noir.org>
src/pools/abstract-pool.ts

index b3b1623f4490346db6286a15fcdb3d82c9f9aba3..2cf21126473cf44d548d7bcd6ee253cb2f4c8b06 100644 (file)
@@ -812,10 +812,9 @@ export abstract class AbstractPool<
    */
   protected internalBackPressure (): boolean {
     return (
-      this.opts.enableTasksQueue === true &&
       this.workerNodes.reduce(
-        (accumulator, workerNode) =>
-          workerNode.info.ready && workerNode.info.backPressure
+        (accumulator, _, workerNodeKey) =>
+          this.isWorkerNodeBackPressured(workerNodeKey)
             ? accumulator + 1
             : accumulator,
         0
@@ -1333,6 +1332,11 @@ export abstract class AbstractPool<
     })
   }
 
+  private isWorkerNodeBackPressured (workerNodeKey: number): boolean {
+    const workerNode = this.workerNodes[workerNodeKey]
+    return workerNode.info.ready && workerNode.info.backPressure
+  }
+
   private isWorkerNodeBusy (workerNodeKey: number): boolean {
     const workerNode = this.workerNodes[workerNodeKey]
     if (this.opts.enableTasksQueue === true) {
@@ -2073,8 +2077,10 @@ export abstract class AbstractPool<
       }),
       ...(this.opts.enableTasksQueue === true && {
         backPressureWorkerNodes: this.workerNodes.reduce(
-          (accumulator, workerNode) =>
-            workerNode.info.backPressure ? accumulator + 1 : accumulator,
+          (accumulator, _, workerNodeKey) =>
+            this.isWorkerNodeBackPressured(workerNodeKey)
+              ? accumulator + 1
+              : accumulator,
           0
         ),
       }),