fix: fix tasks usage initialization
authorJérôme Benoit <jerome.benoit@sap.com>
Wed, 12 Apr 2023 20:22:39 +0000 (22:22 +0200)
committerJérôme Benoit <jerome.benoit@sap.com>
Wed, 12 Apr 2023 20:22:39 +0000 (22:22 +0200)
Signed-off-by: Jérôme Benoit <jerome.benoit@sap.com>
src/pools/abstract-pool.ts
src/utils.ts

index 1c59f74b22b1eaf811e3a9dc0cf3d6bbbd150206..3be40e6d9cc8dd2634ab02569abd6261dca6f326 100644 (file)
@@ -3,7 +3,6 @@ import type { MessageValue, PromiseResponseWrapper } from '../utility-types'
 import {
   DEFAULT_WORKER_CHOICE_STRATEGY_OPTIONS,
   EMPTY_FUNCTION,
-  INITIAL_TASKS_USAGE,
   median
 } from '../utils'
 import { KillBehaviors, isKillBehavior } from '../worker/worker-options'
@@ -21,6 +20,7 @@ import {
   type WorkerChoiceStrategy
 } from './selection-strategies/selection-strategies-types'
 import { WorkerChoiceStrategyContext } from './selection-strategies/worker-choice-strategy-context'
+import { CircularArray } from '../circular-array'
 
 /**
  * Base class that implements some shared logic for all poolifier pools.
@@ -212,7 +212,15 @@ export abstract class AbstractPool<
     this.checkValidWorkerChoiceStrategy(workerChoiceStrategy)
     this.opts.workerChoiceStrategy = workerChoiceStrategy
     for (const workerNode of this.workerNodes) {
-      this.setWorkerNodeTasksUsage(workerNode, INITIAL_TASKS_USAGE)
+      this.setWorkerNodeTasksUsage(workerNode, {
+        run: 0,
+        running: 0,
+        runTime: 0,
+        runTimeHistory: new CircularArray(),
+        avgRunTime: 0,
+        medRunTime: 0,
+        error: 0
+      })
     }
     this.workerChoiceStrategyContext.setWorkerChoiceStrategy(
       workerChoiceStrategy
@@ -518,7 +526,15 @@ export abstract class AbstractPool<
   private pushWorkerNode (worker: Worker): number {
     return this.workerNodes.push({
       worker,
-      tasksUsage: INITIAL_TASKS_USAGE,
+      tasksUsage: {
+        run: 0,
+        running: 0,
+        runTime: 0,
+        runTimeHistory: new CircularArray(),
+        avgRunTime: 0,
+        medRunTime: 0,
+        error: 0
+      },
       tasksQueue: []
     })
   }
index 1d7f81d2d19fb41397a5ecdcbacde6d2d5076dd0..fc328a6c688e2d85f04a04be0e4874584ad5c57c 100644 (file)
@@ -1,6 +1,4 @@
-import { CircularArray } from './circular-array'
 import type { WorkerChoiceStrategyOptions } from './pools/selection-strategies/selection-strategies-types'
-import type { TasksUsage } from './pools/worker'
 
 /**
  * An intentional empty function.
@@ -9,19 +7,6 @@ export const EMPTY_FUNCTION: () => void = Object.freeze(() => {
   /* Intentionally empty */
 })
 
-/**
- * Initial tasks usage statistics.
- */
-export const INITIAL_TASKS_USAGE: TasksUsage = {
-  run: 0,
-  running: 0,
-  runTime: 0,
-  runTimeHistory: new CircularArray(),
-  avgRunTime: 0,
-  medRunTime: 0,
-  error: 0
-}
-
 /**
  * Default worker choice strategy options.
  */