X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Fpools%2Fselection-strategies%2Fround-robin-worker-choice-strategy.ts;h=10bdf8714b8bbd23eaf1fab96051ed11e7094bdd;hb=936fa0fb8e70b2c297938cc9455444486b6daa3e;hp=b023234a202cacc50b8f2505859e4e444bcf8f0f;hpb=949194eb4b838e9d22dcc4d16649521f7b9e79c3;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 b023234a..10bdf871 100644 --- a/src/pools/selection-strategies/round-robin-worker-choice-strategy.ts +++ b/src/pools/selection-strategies/round-robin-worker-choice-strategy.ts @@ -24,7 +24,8 @@ export class RoundRobinWorkerChoiceStrategy< implements IWorkerChoiceStrategy { /** @inheritDoc */ public readonly strategyPolicy: StrategyPolicy = { - useDynamicWorker: true + dynamicWorkerUsage: true, + dynamicWorkerReady: true } /** @inheritDoc */ @@ -48,11 +49,12 @@ export class RoundRobinWorkerChoiceStrategy< } /** @inheritDoc */ - public choose (): number { + public choose (): number | undefined { const chosenWorkerNodeKey = this.nextWorkerNodeKey - do { - this.roundRobinNextWorkerNodeKey() - } while (!this.isWorkerNodeReady(this.nextWorkerNodeKey)) + this.roundRobinNextWorkerNodeKey() + if (!this.isWorkerNodeEligible(this.nextWorkerNodeKey as number)) { + this.nextWorkerNodeKey = undefined + } return chosenWorkerNodeKey } @@ -68,11 +70,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 ?? 0) + 1 return this.nextWorkerNodeKey } }