refactor: cleanup error type
[poolifier.git] / src / pools / selection-strategies / abstract-worker-choice-strategy.ts
index fb3bf707386f8bdb2bb9aac23ccf6db9d851ac96..d017122113cce8c5ef62a8f0812522fba1a354ad 100644 (file)
@@ -93,6 +93,11 @@ export abstract class AbstractWorkerChoiceStrategy<
     }
   }
 
+  protected resetWorkerNodeKeyProperties (): void {
+    this.nextWorkerNodeKey = 0
+    this.previousWorkerNodeKey = 0
+  }
+
   /** @inheritDoc */
   public abstract reset (): boolean
 
@@ -204,6 +209,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()) {