From: Jérôme Benoit Date: Sat, 19 Aug 2023 19:53:20 +0000 (+0200) Subject: refactor: silence sonar X-Git-Tag: v2.6.31~17 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=48e6ef5a44b43a9a8be1c99ef96405af33192e92;p=poolifier.git refactor: silence sonar Signed-off-by: Jérôme Benoit --- diff --git a/src/pools/selection-strategies/abstract-worker-choice-strategy.ts b/src/pools/selection-strategies/abstract-worker-choice-strategy.ts index fb3bf707..cc38d196 100644 --- a/src/pools/selection-strategies/abstract-worker-choice-strategy.ts +++ b/src/pools/selection-strategies/abstract-worker-choice-strategy.ts @@ -204,6 +204,16 @@ export abstract class AbstractWorkerChoiceStrategy< } } + protected checkNextWorkerNodeEligibility ( + chosenWorkerNodeKey: number | undefined + ): void { + if (!this.isWorkerNodeEligible(this.nextWorkerNodeKey as number)) { + this.nextWorkerNodeKey = undefined + this.previousWorkerNodeKey = + chosenWorkerNodeKey ?? this.previousWorkerNodeKey + } + } + protected computeDefaultWorkerWeight (): number { let cpusCycleTimeWeight = 0 for (const cpu of cpus()) { 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 7a50db7b..7968e621 100644 --- a/src/pools/selection-strategies/round-robin-worker-choice-strategy.ts +++ b/src/pools/selection-strategies/round-robin-worker-choice-strategy.ts @@ -45,11 +45,7 @@ export class RoundRobinWorkerChoiceStrategy< 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 - } + this.checkNextWorkerNodeEligibility(chosenWorkerNodeKey) return chosenWorkerNodeKey } diff --git a/src/pools/selection-strategies/weighted-round-robin-worker-choice-strategy.ts b/src/pools/selection-strategies/weighted-round-robin-worker-choice-strategy.ts index 78ad7485..2c03271e 100644 --- a/src/pools/selection-strategies/weighted-round-robin-worker-choice-strategy.ts +++ b/src/pools/selection-strategies/weighted-round-robin-worker-choice-strategy.ts @@ -72,11 +72,7 @@ export class WeightedRoundRobinWorkerChoiceStrategy< public choose (): number | undefined { const chosenWorkerNodeKey = this.nextWorkerNodeKey this.weightedRoundRobinNextWorkerNodeKey() - if (!this.isWorkerNodeEligible(this.nextWorkerNodeKey as number)) { - this.nextWorkerNodeKey = undefined - this.previousWorkerNodeKey = - chosenWorkerNodeKey ?? this.previousWorkerNodeKey - } + this.checkNextWorkerNodeEligibility(chosenWorkerNodeKey) return chosenWorkerNodeKey }