refactor: silence sonar
authorJérôme Benoit <jerome.benoit@sap.com>
Sat, 19 Aug 2023 19:53:20 +0000 (21:53 +0200)
committerJérôme Benoit <jerome.benoit@sap.com>
Sat, 19 Aug 2023 19:53:20 +0000 (21:53 +0200)
Signed-off-by: Jérôme Benoit <jerome.benoit@sap.com>
src/pools/selection-strategies/abstract-worker-choice-strategy.ts
src/pools/selection-strategies/round-robin-worker-choice-strategy.ts
src/pools/selection-strategies/weighted-round-robin-worker-choice-strategy.ts

index fb3bf707386f8bdb2bb9aac23ccf6db9d851ac96..cc38d196941e4611af2235a84899cd82ab55c9f0 100644 (file)
@@ -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()) {
index 7a50db7b6387d5426dd4c4847482c5314f611b74..7968e621d49df510c06ad2bd4899b56770b3b163 100644 (file)
@@ -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
   }
 
index 78ad7485dcc58ddb8c65ebb946fcdc6a34b92f5d..2c03271e329ea0981c3b898e96245aea3ff63669 100644 (file)
@@ -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
   }