refactor: remove unneeded branching in WCS code
authorJérôme Benoit <jerome.benoit@sap.com>
Sat, 19 Aug 2023 22:16:20 +0000 (00:16 +0200)
committerJérôme Benoit <jerome.benoit@sap.com>
Sat, 19 Aug 2023 22:16:20 +0000 (00:16 +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/fair-share-worker-choice-strategy.ts
src/pools/selection-strategies/least-busy-worker-choice-strategy.ts
src/pools/selection-strategies/least-elu-worker-choice-strategy.ts
src/pools/selection-strategies/least-used-worker-choice-strategy.ts

index d017122113cce8c5ef62a8f0812522fba1a354ad..c2b4d1d3d37b56c5101c235fa2f49cfcfb6bd5fd 100644 (file)
@@ -195,20 +195,10 @@ export abstract class AbstractWorkerChoiceStrategy<
   }
 
   /**
-   * Assign to nextWorkerNodeKey property the chosen worker node key.
+   * Check the next worker node eligibility.
    *
    * @param chosenWorkerNodeKey - The chosen worker node key.
    */
-  protected assignChosenWorkerNodeKey (
-    chosenWorkerNodeKey: number | undefined
-  ): void {
-    if (chosenWorkerNodeKey != null) {
-      this.nextWorkerNodeKey = chosenWorkerNodeKey
-    } else {
-      this.nextWorkerNodeKey = undefined
-    }
-  }
-
   protected checkNextWorkerNodeEligibility (
     chosenWorkerNodeKey: number | undefined
   ): void {
index bc8f8b48746ebf185503455241e94d42e8600552..094e9b02f438d711de40431288864a55982cf9cb 100644 (file)
@@ -70,8 +70,7 @@ export class FairShareWorkerChoiceStrategy<
 
   /** @inheritDoc */
   public choose (): number | undefined {
-    const chosenWorkerNodeKey = this.fairShareNextWorkerNodeKey()
-    this.assignChosenWorkerNodeKey(chosenWorkerNodeKey)
+    this.nextWorkerNodeKey = this.fairShareNextWorkerNodeKey()
     return this.nextWorkerNodeKey
   }
 
index 224ca540130f49c37e6b28d5de471e5237dddb14..6fad8939e75aa0f2a3dca8e332c08ba529ba3a83 100644 (file)
@@ -61,8 +61,7 @@ export class LeastBusyWorkerChoiceStrategy<
 
   /** @inheritDoc */
   public choose (): number | undefined {
-    const chosenWorkerNodeKey = this.leastBusyNextWorkerNodeKey()
-    this.assignChosenWorkerNodeKey(chosenWorkerNodeKey)
+    this.nextWorkerNodeKey = this.leastBusyNextWorkerNodeKey()
     return this.nextWorkerNodeKey
   }
 
index 0f992cfaf82d17794def8c9a129dacf91075f2ec..00919f33f58f5878fd381692bfb2009f2c5b611c 100644 (file)
@@ -57,8 +57,7 @@ export class LeastEluWorkerChoiceStrategy<
 
   /** @inheritDoc */
   public choose (): number | undefined {
-    const chosenWorkerNodeKey = this.leastEluNextWorkerNodeKey()
-    this.assignChosenWorkerNodeKey(chosenWorkerNodeKey)
+    this.nextWorkerNodeKey = this.leastEluNextWorkerNodeKey()
     return this.nextWorkerNodeKey
   }
 
index 515b4e935db6e33fd5f3946c4f1b7cb0eb52a5f0..4387d792ef951c2e602308b48d4caffd95e67d53 100644 (file)
@@ -42,8 +42,7 @@ export class LeastUsedWorkerChoiceStrategy<
 
   /** @inheritDoc */
   public choose (): number | undefined {
-    const chosenWorkerNodeKey = this.leastUsedNextWorkerNodeKey()
-    this.assignChosenWorkerNodeKey(chosenWorkerNodeKey)
+    this.nextWorkerNodeKey = this.leastUsedNextWorkerNodeKey()
     return this.nextWorkerNodeKey
   }