From 48e6ef5a44b43a9a8be1c99ef96405af33192e92 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Sat, 19 Aug 2023 21:53:20 +0200 Subject: [PATCH] refactor: silence sonar MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- .../abstract-worker-choice-strategy.ts | 10 ++++++++++ .../round-robin-worker-choice-strategy.ts | 6 +----- .../weighted-round-robin-worker-choice-strategy.ts | 6 +----- 3 files changed, 12 insertions(+), 10 deletions(-) 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 } -- 2.34.1