X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Fpools%2Fselection-strategies%2Fround-robin-worker-choice-strategy.ts;h=7a50db7b6387d5426dd4c4847482c5314f611b74;hb=f6bc9f26d8a0246bbee14b2b03d0bcc41b8aeb52;hp=222a03495db53a789a0038e3ce9e0e41f0e17518;hpb=20016c79549983d09d30b70852ec7fae515d4156;p=poolifier.git diff --git a/src/pools/selection-strategies/round-robin-worker-choice-strategy.ts b/src/pools/selection-strategies/round-robin-worker-choice-strategy.ts index 222a0349..7a50db7b 100644 --- a/src/pools/selection-strategies/round-robin-worker-choice-strategy.ts +++ b/src/pools/selection-strategies/round-robin-worker-choice-strategy.ts @@ -4,7 +4,6 @@ import type { IWorker } from '../worker' import { AbstractWorkerChoiceStrategy } from './abstract-worker-choice-strategy' import type { IWorkerChoiceStrategy, - StrategyPolicy, WorkerChoiceStrategyOptions } from './selection-strategies-types' @@ -22,11 +21,6 @@ export class RoundRobinWorkerChoiceStrategy< > extends AbstractWorkerChoiceStrategy implements IWorkerChoiceStrategy { - /** @inheritDoc */ - public readonly strategyPolicy: StrategyPolicy = { - useDynamicWorker: true - } - /** @inheritDoc */ public constructor ( pool: IPool, @@ -48,9 +42,14 @@ export class RoundRobinWorkerChoiceStrategy< } /** @inheritDoc */ - public choose (): number { + public choose (): number | undefined { const chosenWorkerNodeKey = this.nextWorkerNodeKey this.roundRobinNextWorkerNodeKey() + if (!this.isWorkerNodeEligible(this.nextWorkerNodeKey as number)) { + this.nextWorkerNodeKey = undefined + this.previousWorkerNodeKey = + chosenWorkerNodeKey ?? this.previousWorkerNodeKey + } return chosenWorkerNodeKey } @@ -66,11 +65,11 @@ export class RoundRobinWorkerChoiceStrategy< return true } - private roundRobinNextWorkerNodeKey (): number { + private roundRobinNextWorkerNodeKey (): number | undefined { this.nextWorkerNodeKey = this.nextWorkerNodeKey === this.pool.workerNodes.length - 1 ? 0 - : this.nextWorkerNodeKey + 1 + : (this.nextWorkerNodeKey ?? this.previousWorkerNodeKey) + 1 return this.nextWorkerNodeKey } }