From 23ccf9d796ac950710863515ff45612a0456931d Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Mon, 3 Jul 2023 22:08:57 +0200 Subject: [PATCH] feat: add version to pool information MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- CHANGELOG.md | 1 + rollup.config.mjs | 1 + src/pools/abstract-pool.ts | 8 ++++++++ src/pools/pool.ts | 1 + tests/pools/abstract/abstract-pool.test.js | 5 +++++ tsconfig.json | 4 +++- 6 files changed, 19 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4b767cf7..38bdf2d0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added - Add pool `utilization` ratio to pool information. +- Add `version` to pool information. - Add worker information to worker nodes. ## [2.6.6] - 2023-07-01 diff --git a/rollup.config.mjs b/rollup.config.mjs index 1410f161..d88f9734 100644 --- a/rollup.config.mjs +++ b/rollup.config.mjs @@ -48,6 +48,7 @@ export default { 'node:cluster', 'node:crypto', 'node:events', + 'node:fs', 'node:os', 'node:perf_hooks', 'node:worker_threads' diff --git a/src/pools/abstract-pool.ts b/src/pools/abstract-pool.ts index 69f6a592..03f8c199 100644 --- a/src/pools/abstract-pool.ts +++ b/src/pools/abstract-pool.ts @@ -1,5 +1,6 @@ import crypto from 'node:crypto' import { performance } from 'node:perf_hooks' +import { readFileSync } from 'node:fs' import type { MessageValue, PromiseResponseWrapper } from '../utility-types' import { DEFAULT_WORKER_CHOICE_STRATEGY_OPTIONS, @@ -39,6 +40,12 @@ import { } from './selection-strategies/selection-strategies-types' import { WorkerChoiceStrategyContext } from './selection-strategies/worker-choice-strategy-context' +const version = ( + JSON.parse( + readFileSync(new URL('../../package.json', import.meta.url), 'utf8') + ) as Record +).version as string + /** * Base class that implements some shared logic for all poolifier pools. * @@ -249,6 +256,7 @@ export abstract class AbstractPool< /** @inheritDoc */ public get info (): PoolInfo { return { + version, type: this.type, worker: this.worker, minSize: this.minSize, diff --git a/src/pools/pool.ts b/src/pools/pool.ts index 855ce000..22757f9a 100644 --- a/src/pools/pool.ts +++ b/src/pools/pool.ts @@ -68,6 +68,7 @@ export type PoolEvent = keyof typeof PoolEvents * Pool information. */ export interface PoolInfo { + version: string type: PoolType worker: WorkerType minSize: number diff --git a/tests/pools/abstract/abstract-pool.test.js b/tests/pools/abstract/abstract-pool.test.js index adf2765f..d3a71bc1 100644 --- a/tests/pools/abstract/abstract-pool.test.js +++ b/tests/pools/abstract/abstract-pool.test.js @@ -11,6 +11,7 @@ const { } = require('../../../lib') const { CircularArray } = require('../../../lib/circular-array') const { Queue } = require('../../../lib/queue') +const { version } = require('../../../package.json') describe('Abstract pool test suite', () => { const numberOfWorkers = 2 @@ -393,6 +394,7 @@ describe('Abstract pool test suite', () => { './tests/worker-files/thread/testWorker.js' ) expect(pool.info).toStrictEqual({ + version, type: PoolTypes.fixed, worker: WorkerTypes.thread, minSize: numberOfWorkers, @@ -413,6 +415,7 @@ describe('Abstract pool test suite', () => { './tests/worker-files/cluster/testWorker.js' ) expect(pool.info).toStrictEqual({ + version, type: PoolTypes.dynamic, worker: WorkerTypes.cluster, minSize: numberOfWorkers, @@ -711,6 +714,7 @@ describe('Abstract pool test suite', () => { // So in total numberOfWorkers * 2 times for a loop submitting up to numberOfWorkers * 2 tasks to the dynamic pool with min = max = numberOfWorkers. expect(poolFull).toBe(numberOfWorkers * 2) expect(poolInfo).toStrictEqual({ + version, type: PoolTypes.dynamic, worker: WorkerTypes.thread, minSize: expect.any(Number), @@ -747,6 +751,7 @@ describe('Abstract pool test suite', () => { // So in total numberOfWorkers + 1 times for a loop submitting up to numberOfWorkers * 2 tasks to the fixed pool. expect(poolBusy).toBe(numberOfWorkers + 1) expect(poolInfo).toStrictEqual({ + version, type: PoolTypes.fixed, worker: WorkerTypes.thread, minSize: expect.any(Number), diff --git a/tsconfig.json b/tsconfig.json index 1c8465ed..c2c97a36 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -4,9 +4,11 @@ "target": "ES2022", "module": "ES2022", "outDir": "lib", + "moduleResolution": "Node", "esModuleInterop": true, "declaration": true, - "strict": true + "strict": true, + "forceConsistentCasingInFileNames": true }, "include": ["**/*.ts"], "exclude": ["node_modules", "lib"] -- 2.34.1