fix: fix tasks usage initialization
[poolifier.git] / src / pools / selection-strategies / fair-share-worker-choice-strategy.ts
index c2f85f18ae911f0c8e35bbca6ff11712b360dff8..3f4e95249497897d0f718c4192880fecdc695129 100644 (file)
@@ -19,7 +19,7 @@ interface WorkerVirtualTaskTimestamp {
  *
  * @typeParam Worker - Type of worker which manages the strategy.
  * @typeParam Data - Type of data sent to the worker. This can only be serializable data.
- * @typeParam Response - Type of response of execution. This can only be serializable data.
+ * @typeParam Response - Type of execution response. This can only be serializable data.
  */
 export class FairShareWorkerChoiceStrategy<
     Worker extends IWorker,
@@ -88,11 +88,12 @@ export class FairShareWorkerChoiceStrategy<
       performance.now(),
       this.workerLastVirtualTaskTimestamp.get(workerNodeKey)?.end ?? -Infinity
     )
+    const workerVirtualTaskTRunTime = this.requiredStatistics.medRunTime
+      ? this.pool.workerNodes[workerNodeKey].tasksUsage.medRunTime
+      : this.pool.workerNodes[workerNodeKey].tasksUsage.avgRunTime
     this.workerLastVirtualTaskTimestamp.set(workerNodeKey, {
       start: workerVirtualTaskStartTimestamp,
-      end:
-        workerVirtualTaskStartTimestamp +
-        (this.pool.workerNodes[workerNodeKey].tasksUsage.avgRunTime ?? 0)
+      end: workerVirtualTaskStartTimestamp + (workerVirtualTaskTRunTime ?? 0)
     })
   }
 }