refactor: align worker choice strategy options namespace
[poolifier.git] / src / pools / selection-strategies / selection-strategies-types.ts
index 6ae695ca6dca6141d48cef31dd46c6be5cb08bbb..26fe436d7a8e587b651458e8359a0b4d0a2e27f9 100644 (file)
@@ -7,13 +7,13 @@ export const WorkerChoiceStrategies = Object.freeze({
    */
   ROUND_ROBIN: 'ROUND_ROBIN',
   /**
-   * Less used worker selection strategy.
+   * Least used worker selection strategy.
    */
-  LESS_USED: 'LESS_USED',
+  LEAST_USED: 'LEAST_USED',
   /**
-   * Less busy worker selection strategy.
+   * Least busy worker selection strategy.
    */
-  LESS_BUSY: 'LESS_BUSY',
+  LEAST_BUSY: 'LEAST_BUSY',
   /**
    * Fair share worker selection strategy.
    */
@@ -35,16 +35,32 @@ export const WorkerChoiceStrategies = Object.freeze({
  */
 export type WorkerChoiceStrategy = keyof typeof WorkerChoiceStrategies
 
+/**
+ * Measurement options.
+ */
+interface MeasurementOptions {
+  /**
+   * Set measurement median.
+   */
+  median: boolean
+}
+
 /**
  * Worker choice strategy options.
  */
 export interface WorkerChoiceStrategyOptions {
   /**
-   * Use tasks median run time instead of average run time.
+   * Runtime options.
    *
-   * @defaultValue false
+   * @defaultValue \{ median: false \}
    */
-  medRunTime?: boolean
+  runTime?: MeasurementOptions
+  /**
+   * Wait time options.
+   *
+   * @defaultValue \{ median: false \}
+   */
+  waitTime?: MeasurementOptions
   /**
    * Worker weights to use for weighted round robin worker selection strategy.
    * Weight is the tasks maximum average or median runtime in milliseconds.
@@ -55,23 +71,43 @@ export interface WorkerChoiceStrategyOptions {
 }
 
 /**
- * Pool worker tasks usage statistics requirements.
+ * Measurement statistics requirements.
+ *
+ * @internal
+ */
+interface MeasurementStatisticsRequirements {
+  /**
+   * Require measurement aggregate.
+   */
+  aggregate: boolean
+  /**
+   * Require measurement average.
+   */
+  average: boolean
+  /**
+   * Require measurement median.
+   */
+  median: boolean
+}
+
+/**
+ * Pool worker node worker usage statistics requirements.
  *
  * @internal
  */
-export interface RequiredStatistics {
+export interface TaskStatisticsRequirements {
   /**
-   * Require tasks run time.
+   * Tasks runtime requirements.
    */
-  runTime: boolean
+  runTime: MeasurementStatisticsRequirements
   /**
-   * Require tasks average run time.
+   * Tasks wait time requirements.
    */
-  avgRunTime: boolean
+  waitTime: MeasurementStatisticsRequirements
   /**
-   * Require tasks median run time.
+   * Event loop utilization.
    */
-  medRunTime: boolean
+  elu: boolean
 }
 
 /**
@@ -79,9 +115,9 @@ export interface RequiredStatistics {
  */
 export interface IWorkerChoiceStrategy {
   /**
-   * Required tasks usage statistics.
+   * Tasks statistics requirements.
    */
-  readonly requiredStatistics: RequiredStatistics
+  readonly taskStatisticsRequirements: TaskStatisticsRequirements
   /**
    * Resets strategy internals.
    *