feat: add version to pool information
authorJérôme Benoit <jerome.benoit@sap.com>
Mon, 3 Jul 2023 20:08:57 +0000 (22:08 +0200)
committerJérôme Benoit <jerome.benoit@sap.com>
Mon, 3 Jul 2023 20:08:57 +0000 (22:08 +0200)
Signed-off-by: Jérôme Benoit <jerome.benoit@sap.com>
CHANGELOG.md
rollup.config.mjs
src/pools/abstract-pool.ts
src/pools/pool.ts
tests/pools/abstract/abstract-pool.test.js
tsconfig.json

index 4b767cf7b87266b4daf47c1d76100f1624b78a6e..38bdf2d0e09692448a15b0d63fa3359ff742c130 100644 (file)
@@ -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
index 1410f161af83887ede02a8f98eb6bdcec7d35738..d88f9734de2f431f89c2a79ccc5038b88ee17f98 100644 (file)
@@ -48,6 +48,7 @@ export default {
     'node:cluster',
     'node:crypto',
     'node:events',
+    'node:fs',
     'node:os',
     'node:perf_hooks',
     'node:worker_threads'
index 69f6a592162ee1323fc5681a3905604bfb7782c6..03f8c199be642dda1cac20171d0b2410ef73d1c3 100644 (file)
@@ -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<string, unknown>
+).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,
index 855ce000497aadd1019a052db26707d188b418b1..22757f9a54a841597d0394c51675efa25ac08a5d 100644 (file)
@@ -68,6 +68,7 @@ export type PoolEvent = keyof typeof PoolEvents
  * Pool information.
  */
 export interface PoolInfo {
+  version: string
   type: PoolType
   worker: WorkerType
   minSize: number
index adf2765f7e67bcb68ffb11a534574fa3e18c3907..d3a71bc15f5f44e3fdbefe2f0c9d885e102caeed 100644 (file)
@@ -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),
index 1c8465ed55ac106f66b3a935b9819e59cbd75341..c2c97a3613d255f62ba9449978ae6abb8e87ffc5 100644 (file)
@@ -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"]