Add code sonarlint configuration
[poolifier.git] / src / pools / selection-strategies / selection-strategies-types.ts
index edefcfaac429d8c0d24fa897300650d141ab7f3c..f875c2906ee3a173ffab6790d93aece511b2a0ef 100644 (file)
@@ -1,4 +1,4 @@
-import type { AbstractPoolWorker } from '../abstract-pool-worker'
+import type { IPoolWorker } from '../pool-worker'
 
 /**
  * Enumeration of worker choice strategies.
@@ -11,7 +11,15 @@ export const WorkerChoiceStrategies = Object.freeze({
   /**
    * Less recently used worker selection strategy.
    */
-  LESS_RECENTLY_USED: 'LESS_RECENTLY_USED'
+  LESS_RECENTLY_USED: 'LESS_RECENTLY_USED',
+  /**
+   * Fair share worker selection strategy.
+   */
+  FAIR_SHARE: 'FAIR_SHARE',
+  /**
+   * Weighted round robin worker selection strategy.
+   */
+  WEIGHTED_ROUND_ROBIN: 'WEIGHTED_ROUND_ROBIN'
 } as const)
 
 /**
@@ -19,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 internal statistics.
+   */
+  resetStatistics(): boolean
   /**
-   * Choose a worker in the pool.
+   * Chooses a worker in the pool.
    */
   choose(): Worker
 }