refactor: use kill handler in examples
authorJérôme Benoit <jerome.benoit@sap.com>
Tue, 15 Aug 2023 16:20:47 +0000 (18:20 +0200)
committerJérôme Benoit <jerome.benoit@sap.com>
Tue, 15 Aug 2023 16:20:47 +0000 (18:20 +0200)
Signed-off-by: Jérôme Benoit <jerome.benoit@sap.com>
15 files changed:
examples/typescript/http-server-pool/fastify-cluster/package.json
examples/typescript/http-server-pool/fastify-cluster/pnpm-lock.yaml
examples/typescript/http-server-pool/fastify-cluster/src/worker.ts
examples/typescript/http-server-pool/fastify-hybrid/@types/fastify/index.d.ts
examples/typescript/http-server-pool/fastify-hybrid/package.json
examples/typescript/http-server-pool/fastify-hybrid/pnpm-lock.yaml
examples/typescript/http-server-pool/fastify-hybrid/src/fastify-poolifier.ts
examples/typescript/http-server-pool/fastify-hybrid/src/fastify-worker.ts
examples/typescript/http-server-pool/fastify-worker_threads/@types/fastify/index.d.ts
examples/typescript/http-server-pool/fastify-worker_threads/package.json
examples/typescript/http-server-pool/fastify-worker_threads/pnpm-lock.yaml
examples/typescript/http-server-pool/fastify-worker_threads/src/fastify-poolifier.ts
examples/typescript/websocket-server-pool/ws-hybrid/package.json
examples/typescript/websocket-server-pool/ws-hybrid/pnpm-lock.yaml
examples/typescript/websocket-server-pool/ws-hybrid/src/websocket-server-worker.ts

index 8ce7f71282703c28cb768d1e874b153532fd761b..7b835ddf54322b95f7d60e70156cdd9f31672f7a 100644 (file)
@@ -20,7 +20,7 @@
   "license": "ISC",
   "dependencies": {
     "fastify": "^4.21.0",
-    "poolifier": "^2.6.25"
+    "poolifier": "^2.6.26"
   },
   "devDependencies": {
     "@rollup/plugin-typescript": "^11.1.2",
index 42782e4c6e9a52d205a24d41107a3dfcfea3cfed..8ea6899618a1a9773641febdd9f090e8be8eb23a 100644 (file)
@@ -9,8 +9,8 @@ dependencies:
     specifier: ^4.21.0
     version: 4.21.0
   poolifier:
-    specifier: ^2.6.25
-    version: 2.6.25
+    specifier: ^2.6.26
+    version: 2.6.26
 
 devDependencies:
   '@rollup/plugin-typescript':
@@ -90,15 +90,15 @@ packages:
       tslib:
         optional: true
     dependencies:
-      '@rollup/pluginutils': 5.0.2(rollup@3.28.0)
+      '@rollup/pluginutils': 5.0.3(rollup@3.28.0)
       resolve: 1.22.4
       rollup: 3.28.0
       tslib: 2.6.1
       typescript: 5.1.6
     dev: true
 
-  /@rollup/pluginutils@5.0.2(rollup@3.28.0):
-    resolution: {integrity: sha512-pTd9rIsP92h+B6wWwFbW8RkZv4hiR/xKsqre4SIuAOaOEQRxi0lqLke9k2/7WegC85GgUs9pjmOjCUi3In4vwA==}
+  /@rollup/pluginutils@5.0.3(rollup@3.28.0):
+    resolution: {integrity: sha512-hfllNN4a80rwNQ9QCxhxuHCGHMAvabXqxNdaChUSSadMre7t4iEUI6fFAhBOn/eIYTgYVhBv7vCLsAJ4u3lf3g==}
     engines: {node: '>=14.0.0'}
     peerDependencies:
       rollup: ^1.20.0||^2.0.0||^3.0.0
@@ -610,8 +610,8 @@ packages:
       thread-stream: 2.4.0
     dev: false
 
-  /poolifier@2.6.25:
-    resolution: {integrity: sha512-e8RNC8txuDO7x1ALNMDTUVWyrsMCod3krp/ZIhR+L9Q0KpoywwHekyWnRB4V2PYW/B1yxvXoPbQi1a2hZOfsNw==}
+  /poolifier@2.6.26:
+    resolution: {integrity: sha512-cfcP3oCwtxG5DzxLXicUQjr6ieJzX/5/yT2Nt0tBByhufqtu6V2Son7kJXSHlWrNa08Y39cOaeNrOLCazoJ07w==}
     engines: {node: '>=16.14.0', pnpm: '>=8.6.0'}
     requiresBuild: true
     dev: false
index 3f7b3661f99cd2f51082366eadfc8cbe17ba804a..eb546ef0a9d82c189d2ef5b799395321c7d8df62 100644 (file)
@@ -40,7 +40,11 @@ class FastifyWorker extends ClusterWorker<WorkerData, WorkerResponse> {
   }
 
   public constructor () {
-    super(FastifyWorker.startFastify)
+    super(FastifyWorker.startFastify, {
+      killHandler: async () => {
+        await FastifyWorker.fastify.close()
+      }
+    })
   }
 }
 
index a995923928ed84ecafaf9afcbdc4ddee90884103..38a4b0fafdffb8e0d3961bc715bb46dc1ca07c71 100644 (file)
@@ -13,5 +13,6 @@ declare module 'fastify' {
       name?: string,
       transferList?: TransferListItem[]
     ) => Promise<ThreadWorkerResponse>
+    listTaskFunctions: () => string[]
   }
 }
index 8256c5e431de19a24b2fa5dc5bba1919eb6d15f3..466a3e74dc5ba15353341868327a1621c8e29425 100644 (file)
@@ -21,7 +21,7 @@
   "dependencies": {
     "fastify": "^4.21.0",
     "fastify-plugin": "^4.5.1",
-    "poolifier": "^2.6.25"
+    "poolifier": "^2.6.26"
   },
   "devDependencies": {
     "@rollup/plugin-typescript": "^11.1.2",
index 104427de719a95b6d63a9023e16189442c001fff..306aafd71a9536f8b678df21eb7dee0826b0a38d 100644 (file)
@@ -12,8 +12,8 @@ dependencies:
     specifier: ^4.5.1
     version: 4.5.1
   poolifier:
-    specifier: ^2.6.25
-    version: 2.6.25
+    specifier: ^2.6.26
+    version: 2.6.26
 
 devDependencies:
   '@rollup/plugin-typescript':
@@ -93,15 +93,15 @@ packages:
       tslib:
         optional: true
     dependencies:
-      '@rollup/pluginutils': 5.0.2(rollup@3.28.0)
+      '@rollup/pluginutils': 5.0.3(rollup@3.28.0)
       resolve: 1.22.4
       rollup: 3.28.0
       tslib: 2.6.1
       typescript: 5.1.6
     dev: true
 
-  /@rollup/pluginutils@5.0.2(rollup@3.28.0):
-    resolution: {integrity: sha512-pTd9rIsP92h+B6wWwFbW8RkZv4hiR/xKsqre4SIuAOaOEQRxi0lqLke9k2/7WegC85GgUs9pjmOjCUi3In4vwA==}
+  /@rollup/pluginutils@5.0.3(rollup@3.28.0):
+    resolution: {integrity: sha512-hfllNN4a80rwNQ9QCxhxuHCGHMAvabXqxNdaChUSSadMre7t4iEUI6fFAhBOn/eIYTgYVhBv7vCLsAJ4u3lf3g==}
     engines: {node: '>=14.0.0'}
     peerDependencies:
       rollup: ^1.20.0||^2.0.0||^3.0.0
@@ -617,8 +617,8 @@ packages:
       thread-stream: 2.4.0
     dev: false
 
-  /poolifier@2.6.25:
-    resolution: {integrity: sha512-e8RNC8txuDO7x1ALNMDTUVWyrsMCod3krp/ZIhR+L9Q0KpoywwHekyWnRB4V2PYW/B1yxvXoPbQi1a2hZOfsNw==}
+  /poolifier@2.6.26:
+    resolution: {integrity: sha512-cfcP3oCwtxG5DzxLXicUQjr6ieJzX/5/yT2Nt0tBByhufqtu6V2Son7kJXSHlWrNa08Y39cOaeNrOLCazoJ07w==}
     engines: {node: '>=16.14.0', pnpm: '>=8.6.0'}
     requiresBuild: true
     dev: false
index 6e3a1dbfec643759ef30aecfd767e5f9d1c40e02..2a22fdcc6f57372a81fbe9d34ec3732deb75f0ab 100644 (file)
@@ -40,6 +40,11 @@ const fastifyPoolifierPlugin: FastifyPluginCallback<FastifyPoolifierOptions> = (
         await pool.execute(data, name, transferList)
     )
   }
+  if (!fastify.hasDecorator('listTaskFunctions')) {
+    fastify.decorate('listTaskFunctions', (): string[] =>
+      pool.listTaskFunctions()
+    )
+  }
   done()
 }
 
index 89fc333872ef1fea7603ec58290af8e191f10d49..7a09a1ce38666ea1a0ad45e056adb4a1f89f8034 100644 (file)
@@ -43,7 +43,11 @@ ClusterWorkerResponse
   }
 
   public constructor () {
-    super(FastifyWorker.startFastify)
+    super(FastifyWorker.startFastify, {
+      killHandler: async () => {
+        await FastifyWorker.fastify.close()
+      }
+    })
   }
 }
 
index e2ec4062820d299647132f7ac0306127e0ebe57e..0de82629cd2d369a64d7c9985746ac9cbdd1e3e9 100644 (file)
@@ -11,5 +11,6 @@ declare module 'fastify' {
       name?: string,
       transferList?: TransferListItem[]
     ) => Promise<WorkerResponse>
+    listTaskFunctions: () => string[]
   }
 }
index 7144315aa1cfd50f216a386a57fa22b800eaa4c9..6d2e16130e2d27561b858fbcbfe71fcc582d876e 100644 (file)
@@ -21,7 +21,7 @@
   "dependencies": {
     "fastify": "^4.21.0",
     "fastify-plugin": "^4.5.1",
-    "poolifier": "^2.6.25"
+    "poolifier": "^2.6.26"
   },
   "devDependencies": {
     "@types/node": "^20.5.0",
index b4ff98808b3b822dba7773a44c903c032f84a86a..ff483bef910de4ec195816f3b2022fb0d55f4093 100644 (file)
@@ -12,8 +12,8 @@ dependencies:
     specifier: ^4.5.1
     version: 4.5.1
   poolifier:
-    specifier: ^2.6.25
-    version: 2.6.25
+    specifier: ^2.6.26
+    version: 2.6.26
 
 devDependencies:
   '@types/node':
@@ -288,8 +288,8 @@ packages:
       thread-stream: 2.4.0
     dev: false
 
-  /poolifier@2.6.25:
-    resolution: {integrity: sha512-e8RNC8txuDO7x1ALNMDTUVWyrsMCod3krp/ZIhR+L9Q0KpoywwHekyWnRB4V2PYW/B1yxvXoPbQi1a2hZOfsNw==}
+  /poolifier@2.6.26:
+    resolution: {integrity: sha512-cfcP3oCwtxG5DzxLXicUQjr6ieJzX/5/yT2Nt0tBByhufqtu6V2Son7kJXSHlWrNa08Y39cOaeNrOLCazoJ07w==}
     engines: {node: '>=16.14.0', pnpm: '>=8.6.0'}
     requiresBuild: true
     dev: false
index 15e5656b12abe44477a65dc7efd4a994b51663d7..38c808a0cc2b223239f4ad78a7fb48ad20c8b049 100644 (file)
@@ -39,6 +39,11 @@ const fastifyPoolifierPlugin: FastifyPluginCallback<FastifyPoolifierOptions> = (
       ): Promise<WorkerResponse> => await pool.execute(data, name, transferList)
     )
   }
+  if (!fastify.hasDecorator('listTaskFunctions')) {
+    fastify.decorate('listTaskFunctions', (): string[] =>
+      pool.listTaskFunctions()
+    )
+  }
   done()
 }
 
index f6707eb209d7e03e74afed4452f24161c512c4e1..74912738b1142068677607e0b54790db40ff9500 100644 (file)
@@ -19,7 +19,7 @@
   "author": "",
   "license": "ISC",
   "dependencies": {
-    "poolifier": "^2.6.25",
+    "poolifier": "^2.6.26",
     "ws": "^8.13.0"
   },
   "devDependencies": {
index 5e00a095de9d6f29dbdae7f53a40fa56827e9568..caa1d26cb7c1b9e5f398cc0b06e507ad20f208f3 100644 (file)
@@ -6,8 +6,8 @@ settings:
 
 dependencies:
   poolifier:
-    specifier: ^2.6.25
-    version: 2.6.25
+    specifier: ^2.6.26
+    version: 2.6.26
   ws:
     specifier: ^8.13.0
     version: 8.13.0(bufferutil@4.0.7)(utf-8-validate@6.0.3)
@@ -79,15 +79,15 @@ packages:
       tslib:
         optional: true
     dependencies:
-      '@rollup/pluginutils': 5.0.2(rollup@3.28.0)
+      '@rollup/pluginutils': 5.0.3(rollup@3.28.0)
       resolve: 1.22.4
       rollup: 3.28.0
       tslib: 2.6.1
       typescript: 5.1.6
     dev: true
 
-  /@rollup/pluginutils@5.0.2(rollup@3.28.0):
-    resolution: {integrity: sha512-pTd9rIsP92h+B6wWwFbW8RkZv4hiR/xKsqre4SIuAOaOEQRxi0lqLke9k2/7WegC85GgUs9pjmOjCUi3In4vwA==}
+  /@rollup/pluginutils@5.0.3(rollup@3.28.0):
+    resolution: {integrity: sha512-hfllNN4a80rwNQ9QCxhxuHCGHMAvabXqxNdaChUSSadMre7t4iEUI6fFAhBOn/eIYTgYVhBv7vCLsAJ4u3lf3g==}
     engines: {node: '>=14.0.0'}
     peerDependencies:
       rollup: ^1.20.0||^2.0.0||^3.0.0
@@ -393,8 +393,8 @@ packages:
     engines: {node: '>=8.6'}
     dev: true
 
-  /poolifier@2.6.25:
-    resolution: {integrity: sha512-e8RNC8txuDO7x1ALNMDTUVWyrsMCod3krp/ZIhR+L9Q0KpoywwHekyWnRB4V2PYW/B1yxvXoPbQi1a2hZOfsNw==}
+  /poolifier@2.6.26:
+    resolution: {integrity: sha512-cfcP3oCwtxG5DzxLXicUQjr6ieJzX/5/yT2Nt0tBByhufqtu6V2Son7kJXSHlWrNa08Y39cOaeNrOLCazoJ07w==}
     engines: {node: '>=16.14.0', pnpm: '>=8.6.0'}
     requiresBuild: true
     dev: false
index f495a7211024e75ea38cefa2f55c3a4614e6de77..0a1cbdfd956b04265e277b13c5607dad6af5cc37 100644 (file)
@@ -93,7 +93,11 @@ ClusterWorkerResponse
   }
 
   public constructor () {
-    super(WebSocketServerWorker.startWebSocketServer)
+    super(WebSocketServerWorker.startWebSocketServer, {
+      killHandler: () => {
+        WebSocketServerWorker.wss.close()
+      }
+    })
   }
 }