feat: make the remaining worker choice strategies worker readiness aware
authorJérôme Benoit <jerome.benoit@sap.com>
Tue, 11 Jul 2023 14:56:02 +0000 (16:56 +0200)
committerJérôme Benoit <jerome.benoit@sap.com>
Tue, 11 Jul 2023 14:56:02 +0000 (16:56 +0200)
Signed-off-by: Jérôme Benoit <jerome.benoit@sap.com>
src/pools/abstract-pool.ts
src/pools/selection-strategies/round-robin-worker-choice-strategy.ts
src/pools/selection-strategies/weighted-round-robin-worker-choice-strategy.ts

index 063e40d26b8272d675237c97e28ee9cea9b54c76..a3b46cee0f52e0be63827488730e671c1f316a98 100644 (file)
@@ -1135,6 +1135,7 @@ export abstract class AbstractPool<
    */
   private pushWorkerNode (worker: Worker): number {
     const workerNode = new WorkerNode<Worker, Data>(worker, this.worker)
+    // Flag the worker as ready at pool startup.
     if (this.starting) {
       workerNode.info.ready = true
     }
index 222a03495db53a789a0038e3ce9e0e41f0e17518..b023234a202cacc50b8f2505859e4e444bcf8f0f 100644 (file)
@@ -50,7 +50,9 @@ export class RoundRobinWorkerChoiceStrategy<
   /** @inheritDoc */
   public choose (): number {
     const chosenWorkerNodeKey = this.nextWorkerNodeKey
-    this.roundRobinNextWorkerNodeKey()
+    do {
+      this.roundRobinNextWorkerNodeKey()
+    } while (!this.isWorkerNodeReady(this.nextWorkerNodeKey))
     return chosenWorkerNodeKey
   }
 
index 4921df6dd115899261bd05f6fa2f223f09605e91..fecba414ae1f8b18c29f566192ba577eb60b2288 100644 (file)
@@ -77,7 +77,9 @@ export class WeightedRoundRobinWorkerChoiceStrategy<
   /** @inheritDoc */
   public choose (): number {
     const chosenWorkerNodeKey = this.nextWorkerNodeKey
-    this.weightedRoundRobinNextWorkerNodeKey()
+    do {
+      this.weightedRoundRobinNextWorkerNodeKey()
+    } while (!this.isWorkerNodeReady(this.nextWorkerNodeKey))
     return chosenWorkerNodeKey
   }