docs: fix CoC link
[poolifier.git] / src / pools / selection-strategies / interleaved-weighted-round-robin-worker-choice-strategy.ts
index b034cba1d08d69761b3c8f05fdedf395c4702c0a..15a6c7f48eaac7f0a81e5a30bfd74762a426435d 100644 (file)
@@ -105,6 +105,7 @@ export class InterleavedWeightedRoundRobinWorkerChoiceStrategy<
         const workerWeight =
           this.opts.weights?.[workerNodeKey] ?? this.defaultWorkerWeight
         if (
+          this.isWorkerNodeReady(workerNodeKey) &&
           workerWeight >= this.roundWeights[roundIndex] &&
           this.workerNodeVirtualTaskRunTime < workerWeight
         ) {
@@ -121,18 +122,20 @@ export class InterleavedWeightedRoundRobinWorkerChoiceStrategy<
   }
 
   private interleavedWeightedRoundRobinNextWorkerNodeId (): void {
-    if (
-      this.roundId === this.roundWeights.length - 1 &&
-      this.workerNodeId === this.pool.workerNodes.length - 1
-    ) {
-      this.roundId = 0
-      this.workerNodeId = 0
-    } else if (this.workerNodeId === this.pool.workerNodes.length - 1) {
-      this.roundId = this.roundId + 1
-      this.workerNodeId = 0
-    } else {
-      this.workerNodeId = this.workerNodeId + 1
-    }
+    do {
+      if (
+        this.roundId === this.roundWeights.length - 1 &&
+        this.workerNodeId === this.pool.workerNodes.length - 1
+      ) {
+        this.roundId = 0
+        this.workerNodeId = 0
+      } else if (this.workerNodeId === this.pool.workerNodes.length - 1) {
+        this.roundId = this.roundId + 1
+        this.workerNodeId = 0
+      } else {
+        this.workerNodeId = this.workerNodeId + 1
+      }
+    } while (!this.isWorkerNodeReady(this.workerNodeId))
   }
 
   /** @inheritDoc */