docs: merge pool internal interface to public
[poolifier.git] / src / pools / selection-strategies / weighted-round-robin-worker-choice-strategy.ts
index 1bdc02fb189fcf5f21676af2593f2c24854c99dd..f4bac5d76c4e3b669bb5720b99c03b07eabc577d 100644 (file)
@@ -1,11 +1,12 @@
 import { cpus } from 'node:os'
-import type { IPoolInternal } from '../pool-internal'
 import type { IWorker } from '../worker'
 import { AbstractWorkerChoiceStrategy } from './abstract-worker-choice-strategy'
 import type {
   IWorkerChoiceStrategy,
-  RequiredStatistics
+  RequiredStatistics,
+  WorkerChoiceStrategyOptions
 } from './selection-strategies-types'
+import type { IPool } from '../pool'
 
 /**
  * Virtual task runtime.
@@ -57,9 +58,13 @@ export class WeightedRoundRobinWorkerChoiceStrategy<
    * Constructs a worker choice strategy that selects with a weighted round robin scheduling algorithm.
    *
    * @param pool - The pool instance.
+   * @param opts - The worker choice strategy options.
    */
-  public constructor (pool: IPoolInternal<Worker, Data, Response>) {
-    super(pool)
+  public constructor (
+    pool: IPool<Worker, Data, Response>,
+    opts?: WorkerChoiceStrategyOptions
+  ) {
+    super(pool, opts)
     this.defaultWorkerWeight = this.computeWorkerWeight()
     this.initWorkersTaskRunTime()
   }
@@ -146,7 +151,9 @@ export class WeightedRoundRobinWorkerChoiceStrategy<
   }
 
   private getWorkerVirtualTaskRunTime (workerNodeKey: number): number {
-    return this.pool.workerNodes[workerNodeKey].tasksUsage.avgRunTime
+    return this.requiredStatistics.medRunTime
+      ? this.pool.workerNodes[workerNodeKey].tasksUsage.medRunTime
+      : this.pool.workerNodes[workerNodeKey].tasksUsage.avgRunTime
   }
 
   private computeWorkerWeight (): number {