- this.roundId = roundId
- if (workerNodeId == null) {
- this.previousWorkerNodeKey =
- this.nextWorkerNodeKey ?? this.previousWorkerNodeKey
- }
- 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
+ this.interleavedWeightedRoundRobinNextWorkerNodeId()
+ }
+
+ 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