From: Jérôme Benoit Date: Fri, 21 Jul 2023 22:39:03 +0000 (+0200) Subject: refactor: display queues usage in pool info only if enabled X-Git-Tag: v2.6.21~42^2~2 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=daf86646c7cdb484ec05165a49c12224da11a4c7;p=poolifier.git refactor: display queues usage in pool info only if enabled Signed-off-by: Jérôme Benoit --- diff --git a/src/pools/abstract-pool.ts b/src/pools/abstract-pool.ts index d175cd5b..30b4d01f 100644 --- a/src/pools/abstract-pool.ts +++ b/src/pools/abstract-pool.ts @@ -334,16 +334,20 @@ export abstract class AbstractPool< accumulator + workerNode.usage.tasks.executing, 0 ), - queuedTasks: this.workerNodes.reduce( - (accumulator, workerNode) => - accumulator + workerNode.usage.tasks.queued, - 0 - ), - maxQueuedTasks: this.workerNodes.reduce( - (accumulator, workerNode) => - accumulator + (workerNode.usage.tasks?.maxQueued ?? 0), - 0 - ), + ...(this.opts.enableTasksQueue === true && { + queuedTasks: this.workerNodes.reduce( + (accumulator, workerNode) => + accumulator + workerNode.usage.tasks.queued, + 0 + ) + }), + ...(this.opts.enableTasksQueue === true && { + maxQueuedTasks: this.workerNodes.reduce( + (accumulator, workerNode) => + accumulator + (workerNode.usage.tasks?.maxQueued ?? 0), + 0 + ) + }), failedTasks: this.workerNodes.reduce( (accumulator, workerNode) => accumulator + workerNode.usage.tasks.failed, diff --git a/src/pools/pool.ts b/src/pools/pool.ts index 207a8598..4b9f40f4 100644 --- a/src/pools/pool.ts +++ b/src/pools/pool.ts @@ -74,8 +74,8 @@ export interface PoolInfo { readonly busyWorkerNodes: number readonly executedTasks: number readonly executingTasks: number - readonly queuedTasks: number - readonly maxQueuedTasks: number + readonly queuedTasks?: number + readonly maxQueuedTasks?: number readonly failedTasks: number readonly runTime?: { readonly minimum: number diff --git a/tests/pools/abstract/abstract-pool.test.js b/tests/pools/abstract/abstract-pool.test.js index 2c904362..5496746d 100644 --- a/tests/pools/abstract/abstract-pool.test.js +++ b/tests/pools/abstract/abstract-pool.test.js @@ -478,8 +478,6 @@ describe('Abstract pool test suite', () => { busyWorkerNodes: 0, executedTasks: 0, executingTasks: 0, - queuedTasks: 0, - maxQueuedTasks: 0, failedTasks: 0 }) await pool.destroy() @@ -501,8 +499,6 @@ describe('Abstract pool test suite', () => { busyWorkerNodes: 0, executedTasks: 0, executingTasks: 0, - queuedTasks: 0, - maxQueuedTasks: 0, failedTasks: 0 }) await pool.destroy() @@ -769,8 +765,6 @@ describe('Abstract pool test suite', () => { busyWorkerNodes: expect.any(Number), executedTasks: expect.any(Number), executingTasks: expect.any(Number), - queuedTasks: expect.any(Number), - maxQueuedTasks: expect.any(Number), failedTasks: expect.any(Number) }) await pool.destroy() @@ -803,8 +797,6 @@ describe('Abstract pool test suite', () => { busyWorkerNodes: expect.any(Number), executedTasks: expect.any(Number), executingTasks: expect.any(Number), - queuedTasks: expect.any(Number), - maxQueuedTasks: expect.any(Number), failedTasks: expect.any(Number) }) await pool.destroy() @@ -842,8 +834,6 @@ describe('Abstract pool test suite', () => { busyWorkerNodes: expect.any(Number), executedTasks: expect.any(Number), executingTasks: expect.any(Number), - queuedTasks: expect.any(Number), - maxQueuedTasks: expect.any(Number), failedTasks: expect.any(Number) }) await pool.destroy()