Add support for [cluster settings](https://nodejs.org/api/cluster.html#cluster_cluste...
authorJérôme Benoit <jerome.benoit@sap.com>
Sat, 15 Oct 2022 11:05:36 +0000 (13:05 +0200)
committerJérôme Benoit <jerome.benoit@sap.com>
Sat, 15 Oct 2022 11:05:36 +0000 (13:05 +0200)
Close #98

Signed-off-by: Jérôme Benoit <jerome.benoit@sap.com>
CHANGELOG.md
package-lock.json
package.json
sonar-project.properties
src/pools/cluster/fixed.ts
tests/pools/cluster/fixed.test.js

index ed579f973bb543176ba724b765b91ce6c550a040..e3bfba9b40ee32edb44c7de60945efaabab1feb1 100644 (file)
@@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
 The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
 and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
 
+## [2.3.3] - 2022-15-10
+
+### Added
+
+- Add support for [cluster settings](https://nodejs.org/api/cluster.html#cluster_cluster_settings) in cluster pool options.
+
 ## [2.3.2] - 2022-14-10
 
 ### Changed
index 3ae7ac0207b7203ec3ca92747ce5b10cff41f747..f656a1018ecd4e7c4d37cb70a7f13864ad500cb3 100644 (file)
@@ -1,12 +1,12 @@
 {
   "name": "poolifier",
-  "version": "2.3.2",
+  "version": "2.3.3",
   "lockfileVersion": 2,
   "requires": true,
   "packages": {
     "": {
       "name": "poolifier",
-      "version": "2.3.2",
+      "version": "2.3.3",
       "license": "MIT",
       "devDependencies": {
         "@types/node": "^18.11.0",
index 832a06e585890d7b9fa225b3c9487cc2768daff3..6b35ad9fedbac8207b5ca00f5e0495dbdfa87316 100644 (file)
@@ -1,6 +1,6 @@
 {
   "name": "poolifier",
-  "version": "2.3.2",
+  "version": "2.3.3",
   "description": "A fast, easy to use Node.js Worker Thread Pool and Cluster Pool implementation",
   "main": "lib/index.js",
   "scripts": {
index 893d989424a8e54c3f37e49770b56bcd9592fda8..9d27fa0a361f2099974250e6652f7e9422dce51c 100644 (file)
@@ -3,7 +3,7 @@ sonar.organization=pioardi
 sonar.javascript.lcov.reportPaths=coverage/lcov.info
 sonar.eslint.reportPaths=reports/eslint.json
 sonar.projectName=poolifier
-sonar.projectVersion=2.3.2
+sonar.projectVersion=2.3.3
 sonar.host.url=https://sonarcloud.io
 sonar.sources=src
 sonar.tests=tests
index 7ad425a399d1f08c3c97afbaab9b12272571a580..a98cd647eeb59d925f7bd8c3ed6685abf80c1eaf 100644 (file)
@@ -1,4 +1,4 @@
-import type { Worker } from 'cluster'
+import type { ClusterSettings, Worker } from 'cluster'
 import cluster from 'cluster'
 import type { MessageValue } from '../../utility-types'
 import { AbstractPool } from '../abstract-pool'
@@ -16,6 +16,12 @@ export interface ClusterPoolOptions extends PoolOptions<Worker> {
    */
   // eslint-disable-next-line @typescript-eslint/no-explicit-any
   env?: any
+  /**
+   * Cluster settings.
+   *
+   * @see https://nodejs.org/api/cluster.html#cluster_cluster_settings
+   */
+  settings?: ClusterSettings
 }
 
 /**
@@ -51,9 +57,7 @@ export class FixedClusterPool<
 
   /** @inheritDoc */
   protected setupHook (): void {
-    cluster.setupPrimary({
-      exec: this.filePath
-    })
+    cluster.setupPrimary({ ...this.opts.settings, exec: this.filePath })
   }
 
   /** @inheritDoc */
index a05ccc0f60e73865df231d046cf6c3a4b2d9b8d5..e00e5fa331d7231d0cacd862c22adeb29c6c9f66 100644 (file)
@@ -137,6 +137,29 @@ describe('Fixed cluster pool test suite', () => {
     expect(numberOfExitEvents).toBe(numberOfWorkers)
   })
 
+  it('Verify that cluster pool options are checked', async () => {
+    const workerFilePath = './tests/worker-files/cluster/testWorker.js'
+    let pool1 = new FixedClusterPool(numberOfWorkers, workerFilePath)
+    expect(pool1.opts.env).toBeUndefined()
+    expect(pool1.opts.settings).toBeUndefined()
+    await pool1.destroy()
+    pool1 = new FixedClusterPool(numberOfWorkers, workerFilePath, {
+      env: { TEST: 'test' },
+      settings: { args: ['--use', 'http'], silent: true }
+    })
+    expect(pool1.opts.env).toStrictEqual({ TEST: 'test' })
+    expect(pool1.opts.settings).toStrictEqual({
+      args: ['--use', 'http'],
+      silent: true
+    })
+    expect({ ...pool1.opts.settings, exec: workerFilePath }).toStrictEqual({
+      args: ['--use', 'http'],
+      silent: true,
+      exec: workerFilePath
+    })
+    await pool1.destroy()
+  })
+
   it('Should work even without opts in input', async () => {
     const pool1 = new FixedClusterPool(
       numberOfWorkers,