docs: add changelog entry
[poolifier.git] / src / pools / selection-strategies / abstract-worker-choice-strategy.ts
index 5ec7cedc0f9dc0f2f4a1079302a94d515c5d4281..f1d7dcf405b2e565f150137aa87e4cab1a79bd6d 100644 (file)
@@ -116,40 +116,28 @@ export abstract class AbstractWorkerChoiceStrategy<
     this.setTaskStatisticsRequirements(this.opts)
   }
 
-  /**
-   * Whether the worker node is ready or not.
-   *
-   * @param workerNodeKey - The worker node key.
-   * @returns Whether the worker node is ready or not.
-   */
-  private isWorkerNodeReady (workerNodeKey: number): boolean {
-    return this.pool.workerNodes[workerNodeKey].info.ready
+  /** @inheritDoc */
+  public hasPoolWorkerNodesReady (): boolean {
+    return this.pool.workerNodes.some(workerNode => workerNode.info.ready)
   }
 
   /**
-   * Whether the worker node has back pressure or not (i.e. its tasks queue is full).
+   * Whether the worker node is ready or not.
    *
    * @param workerNodeKey - The worker node key.
-   * @returns `true` if the worker node has back pressure, `false` otherwise.
+   * @returns Whether the worker node is ready or not.
    */
-  private hasWorkerNodeBackPressure (workerNodeKey: number): boolean {
-    return this.pool.hasWorkerNodeBackPressure(workerNodeKey)
+  protected isWorkerNodeReady (workerNodeKey: number): boolean {
+    return this.pool.workerNodes[workerNodeKey]?.info?.ready ?? false
   }
 
   /**
-   * Whether the worker node is eligible or not.
-   * A worker node is eligible if it is ready and does not have back pressure.
-   *
-   * @param workerNodeKey - The worker node key.
-   * @returns `true` if the worker node is eligible, `false` otherwise.
-   * @see {@link isWorkerNodeReady}
-   * @see {@link hasWorkerNodeBackPressure}
+   * Check the next worker node readiness.
    */
-  protected isWorkerNodeEligible (workerNodeKey: number): boolean {
-    return (
-      this.isWorkerNodeReady(workerNodeKey) &&
-      !this.hasWorkerNodeBackPressure(workerNodeKey)
-    )
+  protected checkNextWorkerNodeReadiness (): void {
+    if (!this.isWorkerNodeReady(this.nextWorkerNodeKey as number)) {
+      delete this.nextWorkerNodeKey
+    }
   }
 
   /**
@@ -203,15 +191,6 @@ export abstract class AbstractWorkerChoiceStrategy<
     this.previousWorkerNodeKey = workerNodeKey ?? this.previousWorkerNodeKey
   }
 
-  /**
-   * Check the next worker node eligibility.
-   */
-  protected checkNextWorkerNodeEligibility (): void {
-    if (!this.isWorkerNodeEligible(this.nextWorkerNodeKey as number)) {
-      this.nextWorkerNodeKey = undefined
-    }
-  }
-
   protected computeDefaultWorkerWeight (): number {
     let cpusCycleTimeWeight = 0
     for (const cpu of cpus()) {