X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Fpools%2Fselection-strategies%2Fround-robin-worker-choice-strategy.ts;h=7c49cec75689a8ca64aa101b51ec8f86890f1409;hb=3c8a79b4b146fb20de682c19d8b409bfbdf05df4;hp=7968e621d49df510c06ad2bd4899b56770b3b163;hpb=b8508dfc38a7612364981ad5b01811708193f9a2;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 7968e621..7c49cec7 100644 --- a/src/pools/selection-strategies/round-robin-worker-choice-strategy.ts +++ b/src/pools/selection-strategies/round-robin-worker-choice-strategy.ts @@ -32,7 +32,7 @@ export class RoundRobinWorkerChoiceStrategy< /** @inheritDoc */ public reset (): boolean { - this.nextWorkerNodeKey = 0 + this.resetWorkerNodeKeyProperties() return true } @@ -44,19 +44,28 @@ export class RoundRobinWorkerChoiceStrategy< /** @inheritDoc */ public choose (): number | undefined { const chosenWorkerNodeKey = this.nextWorkerNodeKey + this.setPreviousWorkerNodeKey(chosenWorkerNodeKey) this.roundRobinNextWorkerNodeKey() - this.checkNextWorkerNodeEligibility(chosenWorkerNodeKey) + this.checkNextWorkerNodeReadiness() return chosenWorkerNodeKey } /** @inheritDoc */ public remove (workerNodeKey: number): boolean { - if (this.nextWorkerNodeKey === workerNodeKey) { - if (this.pool.workerNodes.length === 0) { - this.nextWorkerNodeKey = 0 - } else if (this.nextWorkerNodeKey > this.pool.workerNodes.length - 1) { - this.nextWorkerNodeKey = this.pool.workerNodes.length - 1 - } + if (this.pool.workerNodes.length === 0) { + this.reset() + } + if ( + this.nextWorkerNodeKey === workerNodeKey && + this.nextWorkerNodeKey > this.pool.workerNodes.length - 1 + ) { + this.nextWorkerNodeKey = this.pool.workerNodes.length - 1 + } + if ( + this.previousWorkerNodeKey === workerNodeKey && + this.previousWorkerNodeKey > this.pool.workerNodes.length - 1 + ) { + this.previousWorkerNodeKey = this.pool.workerNodes.length - 1 } return true }