X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Fpools%2Fselection-strategies%2Fround-robin-worker-choice-strategy.ts;h=7968e621d49df510c06ad2bd4899b56770b3b163;hb=1079e6ed099b03189005b33702c1e9fa912c74d1;hp=fdf5ac84fddf87235b1d7732e81f2ccff3aae53b;hpb=9b1068374b1a52479b07e1e22b692289d5579237;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 fdf5ac84..7968e621 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,10 @@ export class RoundRobinWorkerChoiceStrategy< } /** @inheritDoc */ - public choose (): number { + public choose (): number | undefined { const chosenWorkerNodeKey = this.nextWorkerNodeKey this.roundRobinNextWorkerNodeKey() + this.checkNextWorkerNodeEligibility(chosenWorkerNodeKey) return chosenWorkerNodeKey } @@ -66,10 +61,11 @@ export class RoundRobinWorkerChoiceStrategy< return true } - private roundRobinNextWorkerNodeKey (): void { + 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 } }