refactor: cleanup variables namespace
[poolifier.git] / src / pools / abstract-pool.ts
index c200d5317da6ba47c1154cdeb15a9b5ca5c9ee30..cb5d4ce7f60d81129ed9015108e10b14c4cbef80 100644 (file)
@@ -426,7 +426,7 @@ export abstract class AbstractPool<
    * @returns The pool utilization.
    */
   private get utilization (): number {
-    const poolRunTimeCapacity =
+    const poolTimeCapacity =
       (performance.now() - this.startTimestamp) * this.maxSize
     const totalTasksRunTime = this.workerNodes.reduce(
       (accumulator, workerNode) =>
@@ -438,7 +438,7 @@ export abstract class AbstractPool<
         accumulator + (workerNode.usage.waitTime?.aggregate ?? 0),
       0
     )
-    return (totalTasksRunTime + totalTasksWaitTime) / poolRunTimeCapacity
+    return (totalTasksRunTime + totalTasksWaitTime) / poolTimeCapacity
   }
 
   /**
@@ -474,6 +474,12 @@ export abstract class AbstractPool<
       ?.worker
   }
 
+  /**
+   * Checks if the worker id sent in the received message from a worker is valid.
+   *
+   * @param message - The received message.
+   * @throws {@link https://nodejs.org/api/errors.html#class-error} If the worker id is invalid.
+   */
   private checkMessageWorkerId (message: MessageValue<Response>): void {
     if (
       message.workerId != null &&
@@ -950,9 +956,6 @@ export abstract class AbstractPool<
       if (this.emitter != null) {
         this.emitter.emit(PoolEvents.error, error)
       }
-      if (this.opts.enableTasksQueue === true) {
-        this.redistributeQueuedTasks(worker)
-      }
       if (this.opts.restartWorkerOnError === true && !this.starting) {
         if (this.getWorkerInfo(this.getWorkerNodeKey(worker)).dynamic) {
           this.createAndSetupDynamicWorker()
@@ -960,6 +963,9 @@ export abstract class AbstractPool<
           this.createAndSetupWorker()
         }
       }
+      if (this.opts.enableTasksQueue === true) {
+        this.redistributeQueuedTasks(worker)
+      }
     })
     worker.on('online', this.opts.onlineHandler ?? EMPTY_FUNCTION)
     worker.on('exit', this.opts.exitHandler ?? EMPTY_FUNCTION)