Move worker choice strategy tests into in its own file
[poolifier.git] / src / pools / selection-strategies / selection-strategies-types.ts
index 359cfb948c6334dc507a3d0894149790aef584f9..499b8e489e744a3fad453391b8e4e664c90eac94 100644 (file)
@@ -1,4 +1,4 @@
-import type { AbstractPoolWorker } from '../abstract-pool-worker'
+import type { IPoolWorker } from '../pool-worker'
 
 /**
  * Enumeration of worker choice strategies.
@@ -12,6 +12,10 @@ export const WorkerChoiceStrategies = Object.freeze({
    * Less recently used worker selection strategy.
    */
   LESS_RECENTLY_USED: 'LESS_RECENTLY_USED',
+  /**
+   * Fair share worker selection strategy.
+   */
+  FAIR_SHARE: 'FAIR_SHARE',
   /**
    * Weighted round robin worker selection strategy.
    */
@@ -23,18 +27,33 @@ export const WorkerChoiceStrategies = Object.freeze({
  */
 export type WorkerChoiceStrategy = keyof typeof WorkerChoiceStrategies
 
+/**
+ * Pool tasks usage statistics requirements.
+ */
+export type RequiredStatistics = {
+  runTime: boolean
+}
+
 /**
  * Worker choice strategy interface.
  *
  * @template Worker Type of worker which manages the strategy.
  */
-export interface IWorkerChoiceStrategy<Worker extends AbstractPoolWorker> {
+export interface IWorkerChoiceStrategy<Worker extends IPoolWorker> {
   /**
    * Is the pool attached to the strategy dynamic?.
    */
-  isDynamicPool: boolean
+  readonly isDynamicPool: boolean
+  /**
+   * Required pool tasks usage statistics.
+   */
+  readonly requiredStatistics: RequiredStatistics
+  /**
+   * Resets strategy internals (counters, statistics, etc.).
+   */
+  reset(): boolean
   /**
-   * Choose a worker in the pool.
+   * Chooses a worker in the pool.
    */
   choose(): Worker
 }