>
extends AbstractWorkerChoiceStrategy<Worker, Data, Response>
implements IWorkerChoiceStrategy {
>
extends AbstractWorkerChoiceStrategy<Worker, Data, Response>
implements IWorkerChoiceStrategy {
let workerNodeId: number | undefined
for (
let roundIndex = this.roundId;
roundIndex < this.roundWeights.length;
roundIndex++
) {
let workerNodeId: number | undefined
for (
let roundIndex = this.roundId;
roundIndex < this.roundWeights.length;
roundIndex++
) {
workerNodeKey < this.pool.workerNodes.length;
workerNodeKey++
) {
const workerWeight =
this.opts.weights?.[workerNodeKey] ?? this.defaultWorkerWeight
workerNodeKey < this.pool.workerNodes.length;
workerNodeKey++
) {
const workerWeight =
this.opts.weights?.[workerNodeKey] ?? this.defaultWorkerWeight
- // if (this.isWorkerNodeReady(workerNodeKey) && workerWeight >= this.roundWeights[roundIndex]) {
- if (workerWeight >= this.roundWeights[roundIndex]) {
- roundId = roundIndex
+ if (
+ this.isWorkerNodeEligible(workerNodeKey) &&
+ workerWeight >= this.roundWeights[roundIndex]
+ ) {
- this.roundId = roundId ?? 0
- this.nextWorkerNodeKey = workerNodeId ?? 0
+ 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
} else {
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 {