feat: add task statistics to pool info: runTime and waitTime
[poolifier.git] / src / pools / abstract-pool.ts
index 95df53b2861293c72e2ef6c1e00fa4a4fc5f2c21..fc703d144f2862690c078aef485a72ad74328c2e 100644 (file)
@@ -297,7 +297,37 @@ export abstract class AbstractPool<
         (accumulator, workerNode) =>
           accumulator + workerNode.usage.tasks.failed,
         0
-      )
+      ),
+      ...(this.workerChoiceStrategyContext.getTaskStatisticsRequirements()
+        .runTime.aggregate && {
+        runTime: {
+          minimum: Math.min(
+            ...this.workerNodes.map(
+              workerNode => workerNode.usage.runTime.minimum
+            )
+          ),
+          maximum: Math.max(
+            ...this.workerNodes.map(
+              workerNode => workerNode.usage.runTime.maximum
+            )
+          )
+        }
+      }),
+      ...(this.workerChoiceStrategyContext.getTaskStatisticsRequirements()
+        .waitTime.aggregate && {
+        waitTime: {
+          minimum: Math.min(
+            ...this.workerNodes.map(
+              workerNode => workerNode.usage.waitTime.minimum
+            )
+          ),
+          maximum: Math.max(
+            ...this.workerNodes.map(
+              workerNode => workerNode.usage.waitTime.maximum
+            )
+          )
+        }
+      })
     }
   }