From: Jérôme Benoit Date: Mon, 10 Oct 2022 12:33:02 +0000 (+0200) Subject: Fix task runtime statistics usage calculation logic X-Git-Tag: v2.3.1~42 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=675bb8097982bce5bbe64e6332340373aa4aed3f;p=poolifier.git Fix task runtime statistics usage calculation logic Signed-off-by: Jérôme Benoit --- diff --git a/src/pools/abstract-pool.ts b/src/pools/abstract-pool.ts index e204e124..0136f048 100644 --- a/src/pools/abstract-pool.ts +++ b/src/pools/abstract-pool.ts @@ -226,7 +226,7 @@ export abstract class AbstractPool< } /** - * Shut down given worker. + * Shutdowns given worker. * * @param worker A worker within `workers`. */ @@ -283,7 +283,7 @@ export abstract class AbstractPool< } /** - * Choose a worker for the next task. + * Chooses a worker for the next task. * * The default implementation uses a round robin algorithm to distribute the load. * @@ -294,7 +294,7 @@ export abstract class AbstractPool< } /** - * Send a message to the given worker. + * Sends a message to the given worker. * * @param worker The worker which should receive the message. * @param message The message. @@ -457,9 +457,11 @@ export abstract class AbstractPool< .requiredStatistics.runTime === true ) { const tasksUsage = this.workersTasksUsage.get(worker) - if (tasksUsage !== undefined && tasksUsage.run !== 0) { + if (tasksUsage !== undefined) { tasksUsage.runTime += taskRunTime ?? 0 - tasksUsage.avgRunTime = tasksUsage.runTime / tasksUsage.run + if (tasksUsage.run !== 0) { + tasksUsage.avgRunTime = tasksUsage.runTime / tasksUsage.run + } this.workersTasksUsage.set(worker, tasksUsage) } else { throw new Error(WORKER_NOT_FOUND_TASKS_USAGE_MAP) diff --git a/src/pools/pool.ts b/src/pools/pool.ts index 8da89156..6f677da8 100644 --- a/src/pools/pool.ts +++ b/src/pools/pool.ts @@ -53,7 +53,7 @@ export interface IPool { */ execute(data: Data): Promise /** - * Shut down every current worker in this pool. + * Shutdowns every current worker in this pool. */ destroy(): Promise /**