- this.roundId = roundId as number
- this.nextWorkerNodeKey = workerNodeId
- const chosenWorkerNodeKey = this.nextWorkerNodeKey
- if (this.nextWorkerNodeKey === this.pool.workerNodes.length - 1) {
- this.nextWorkerNodeKey = 0
- this.roundId =
- this.roundId === this.roundWeights.length - 1 ? 0 : this.roundId + 1
- } else {
- this.nextWorkerNodeKey = (this.nextWorkerNodeKey ?? 0) + 1
- }
- return chosenWorkerNodeKey
+ this.interleavedWeightedRoundRobinNextWorkerNodeId()
+ }
+
+ private interleavedWeightedRoundRobinNextWorkerNodeId (): void {
+ 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))