refactor: add task function name to task performance
[poolifier.git] / src / pools / selection-strategies / least-busy-worker-choice-strategy.ts
index 31fa281aa75dd0dcbf63fffe1d2508f0277d3f6a..928b1b2a932488132e3dcbb5a3c8b3d2be4b9892 100644 (file)
@@ -1,4 +1,7 @@
-import { DEFAULT_WORKER_CHOICE_STRATEGY_OPTIONS } from '../../utils'
+import {
+  DEFAULT_MEASUREMENT_STATISTICS_REQUIREMENTS,
+  DEFAULT_WORKER_CHOICE_STRATEGY_OPTIONS
+} from '../../utils'
 import type { IPool } from '../pool'
 import type { IWorker } from '../worker'
 import { AbstractWorkerChoiceStrategy } from './abstract-worker-choice-strategy'
@@ -34,11 +37,7 @@ export class LeastBusyWorkerChoiceStrategy<
       average: false,
       median: false
     },
-    elu: {
-      aggregate: false,
-      average: false,
-      median: false
-    }
+    elu: DEFAULT_MEASUREMENT_STATISTICS_REQUIREMENTS
   }
 
   /** @inheritDoc */
@@ -65,8 +64,8 @@ export class LeastBusyWorkerChoiceStrategy<
     let minTime = Infinity
     for (const [workerNodeKey, workerNode] of this.pool.workerNodes.entries()) {
       const workerTime =
-        workerNode.workerUsage.runTime.aggregate +
-        workerNode.workerUsage.waitTime.aggregate
+        (workerNode.usage.runTime?.aggregate ?? 0) +
+        (workerNode.usage.waitTime?.aggregate ?? 0)
       if (workerTime === 0) {
         this.nextWorkerNodeId = workerNodeKey
         break