feat: add helper to get the worker wait time in worker choice strategies
authorJérôme Benoit <jerome.benoit@piment-noir.org>
Wed, 31 May 2023 09:31:13 +0000 (11:31 +0200)
committerJérôme Benoit <jerome.benoit@piment-noir.org>
Wed, 31 May 2023 09:31:13 +0000 (11:31 +0200)
code

Signed-off-by: Jérôme Benoit <jerome.benoit@piment-noir.org>
src/pools/selection-strategies/abstract-worker-choice-strategy.ts

index efa9578d8b2f889630aadec6da595ded93cd087f..2026e67432170a39460c3de00d0f750b1595934d 100644 (file)
@@ -112,6 +112,20 @@ export abstract class AbstractWorkerChoiceStrategy<
       : this.pool.workerNodes[workerNodeKey].tasksUsage.avgRunTime
   }
 
+  /**
+   * Gets the worker task wait time.
+   * If the required statistics are `avgWaitTime`, the average wait time is returned.
+   * If the required statistics are `medWaitTime`, the median wait time is returned.
+   *
+   * @param workerNodeKey - The worker node key.
+   * @returns The worker task wait time.
+   */
+  protected getWorkerWaitTime (workerNodeKey: number): number {
+    return this.requiredStatistics.medWaitTime
+      ? this.pool.workerNodes[workerNodeKey].tasksUsage.medWaitTime
+      : this.pool.workerNodes[workerNodeKey].tasksUsage.avgWaitTime
+  }
+
   /**
    * Finds the first free worker node key based on the number of tasks the worker has applied.
    *