refactor: worker choice strategies remove() simplification
authorJérôme Benoit <jerome.benoit@sap.com>
Sun, 7 May 2023 20:57:11 +0000 (22:57 +0200)
committerJérôme Benoit <jerome.benoit@sap.com>
Sun, 7 May 2023 20:57:11 +0000 (22:57 +0200)
Signed-off-by: Jérôme Benoit <jerome.benoit@sap.com>
src/pools/selection-strategies/round-robin-worker-choice-strategy.ts
src/pools/selection-strategies/weighted-round-robin-worker-choice-strategy.ts

index 5e35636af62e77d5b56720344c14c274a0c0a97e..e99383caf977bec57a28d158b7c147806ed41fcb 100644 (file)
@@ -61,11 +61,8 @@ export class RoundRobinWorkerChoiceStrategy<
     if (this.nextWorkerNodeId === workerNodeKey) {
       if (this.pool.workerNodes.length === 0) {
         this.nextWorkerNodeId = 0
-      } else {
-        this.nextWorkerNodeId =
-          this.nextWorkerNodeId > this.pool.workerNodes.length - 1
-            ? this.pool.workerNodes.length - 1
-            : this.nextWorkerNodeId
+      } else if (this.nextWorkerNodeId > this.pool.workerNodes.length - 1) {
+        this.nextWorkerNodeId = this.pool.workerNodes.length - 1
       }
     }
     return true
index 1817394933978fcc9a18a4052dcec1c44efe5201..5d8bbe2f1e4466bdfa12b0167d79ee53fc94e065 100644 (file)
@@ -91,11 +91,8 @@ export class WeightedRoundRobinWorkerChoiceStrategy<
     if (this.currentWorkerNodeId === workerNodeKey) {
       if (this.pool.workerNodes.length === 0) {
         this.currentWorkerNodeId = 0
-      } else {
-        this.currentWorkerNodeId =
-          this.currentWorkerNodeId > this.pool.workerNodes.length - 1
-            ? this.pool.workerNodes.length - 1
-            : this.currentWorkerNodeId
+      } else if (this.currentWorkerNodeId > this.pool.workerNodes.length - 1) {
+        this.currentWorkerNodeId = this.pool.workerNodes.length - 1
       }
       this.workerVirtualTaskRunTime = 0
     }