From: Jérôme Benoit Date: Tue, 15 Aug 2023 16:20:47 +0000 (+0200) Subject: refactor: use kill handler in examples X-Git-Tag: v2.6.27~9 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=5daad283d56413b7287cca894637a35e51a1222c;p=poolifier.git refactor: use kill handler in examples Signed-off-by: Jérôme Benoit --- diff --git a/examples/typescript/http-server-pool/fastify-cluster/package.json b/examples/typescript/http-server-pool/fastify-cluster/package.json index 8ce7f712..7b835ddf 100644 --- a/examples/typescript/http-server-pool/fastify-cluster/package.json +++ b/examples/typescript/http-server-pool/fastify-cluster/package.json @@ -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", diff --git a/examples/typescript/http-server-pool/fastify-cluster/pnpm-lock.yaml b/examples/typescript/http-server-pool/fastify-cluster/pnpm-lock.yaml index 42782e4c..8ea68996 100644 --- a/examples/typescript/http-server-pool/fastify-cluster/pnpm-lock.yaml +++ b/examples/typescript/http-server-pool/fastify-cluster/pnpm-lock.yaml @@ -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 diff --git a/examples/typescript/http-server-pool/fastify-cluster/src/worker.ts b/examples/typescript/http-server-pool/fastify-cluster/src/worker.ts index 3f7b3661..eb546ef0 100644 --- a/examples/typescript/http-server-pool/fastify-cluster/src/worker.ts +++ b/examples/typescript/http-server-pool/fastify-cluster/src/worker.ts @@ -40,7 +40,11 @@ class FastifyWorker extends ClusterWorker { } public constructor () { - super(FastifyWorker.startFastify) + super(FastifyWorker.startFastify, { + killHandler: async () => { + await FastifyWorker.fastify.close() + } + }) } } diff --git a/examples/typescript/http-server-pool/fastify-hybrid/@types/fastify/index.d.ts b/examples/typescript/http-server-pool/fastify-hybrid/@types/fastify/index.d.ts index a9959239..38a4b0fa 100644 --- a/examples/typescript/http-server-pool/fastify-hybrid/@types/fastify/index.d.ts +++ b/examples/typescript/http-server-pool/fastify-hybrid/@types/fastify/index.d.ts @@ -13,5 +13,6 @@ declare module 'fastify' { name?: string, transferList?: TransferListItem[] ) => Promise + listTaskFunctions: () => string[] } } diff --git a/examples/typescript/http-server-pool/fastify-hybrid/package.json b/examples/typescript/http-server-pool/fastify-hybrid/package.json index 8256c5e4..466a3e74 100644 --- a/examples/typescript/http-server-pool/fastify-hybrid/package.json +++ b/examples/typescript/http-server-pool/fastify-hybrid/package.json @@ -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", diff --git a/examples/typescript/http-server-pool/fastify-hybrid/pnpm-lock.yaml b/examples/typescript/http-server-pool/fastify-hybrid/pnpm-lock.yaml index 104427de..306aafd7 100644 --- a/examples/typescript/http-server-pool/fastify-hybrid/pnpm-lock.yaml +++ b/examples/typescript/http-server-pool/fastify-hybrid/pnpm-lock.yaml @@ -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 diff --git a/examples/typescript/http-server-pool/fastify-hybrid/src/fastify-poolifier.ts b/examples/typescript/http-server-pool/fastify-hybrid/src/fastify-poolifier.ts index 6e3a1dbf..2a22fdcc 100644 --- a/examples/typescript/http-server-pool/fastify-hybrid/src/fastify-poolifier.ts +++ b/examples/typescript/http-server-pool/fastify-hybrid/src/fastify-poolifier.ts @@ -40,6 +40,11 @@ const fastifyPoolifierPlugin: FastifyPluginCallback = ( await pool.execute(data, name, transferList) ) } + if (!fastify.hasDecorator('listTaskFunctions')) { + fastify.decorate('listTaskFunctions', (): string[] => + pool.listTaskFunctions() + ) + } done() } diff --git a/examples/typescript/http-server-pool/fastify-hybrid/src/fastify-worker.ts b/examples/typescript/http-server-pool/fastify-hybrid/src/fastify-worker.ts index 89fc3338..7a09a1ce 100644 --- a/examples/typescript/http-server-pool/fastify-hybrid/src/fastify-worker.ts +++ b/examples/typescript/http-server-pool/fastify-hybrid/src/fastify-worker.ts @@ -43,7 +43,11 @@ ClusterWorkerResponse } public constructor () { - super(FastifyWorker.startFastify) + super(FastifyWorker.startFastify, { + killHandler: async () => { + await FastifyWorker.fastify.close() + } + }) } } diff --git a/examples/typescript/http-server-pool/fastify-worker_threads/@types/fastify/index.d.ts b/examples/typescript/http-server-pool/fastify-worker_threads/@types/fastify/index.d.ts index e2ec4062..0de82629 100644 --- a/examples/typescript/http-server-pool/fastify-worker_threads/@types/fastify/index.d.ts +++ b/examples/typescript/http-server-pool/fastify-worker_threads/@types/fastify/index.d.ts @@ -11,5 +11,6 @@ declare module 'fastify' { name?: string, transferList?: TransferListItem[] ) => Promise + listTaskFunctions: () => string[] } } diff --git a/examples/typescript/http-server-pool/fastify-worker_threads/package.json b/examples/typescript/http-server-pool/fastify-worker_threads/package.json index 7144315a..6d2e1613 100644 --- a/examples/typescript/http-server-pool/fastify-worker_threads/package.json +++ b/examples/typescript/http-server-pool/fastify-worker_threads/package.json @@ -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", diff --git a/examples/typescript/http-server-pool/fastify-worker_threads/pnpm-lock.yaml b/examples/typescript/http-server-pool/fastify-worker_threads/pnpm-lock.yaml index b4ff9880..ff483bef 100644 --- a/examples/typescript/http-server-pool/fastify-worker_threads/pnpm-lock.yaml +++ b/examples/typescript/http-server-pool/fastify-worker_threads/pnpm-lock.yaml @@ -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 diff --git a/examples/typescript/http-server-pool/fastify-worker_threads/src/fastify-poolifier.ts b/examples/typescript/http-server-pool/fastify-worker_threads/src/fastify-poolifier.ts index 15e5656b..38c808a0 100644 --- a/examples/typescript/http-server-pool/fastify-worker_threads/src/fastify-poolifier.ts +++ b/examples/typescript/http-server-pool/fastify-worker_threads/src/fastify-poolifier.ts @@ -39,6 +39,11 @@ const fastifyPoolifierPlugin: FastifyPluginCallback = ( ): Promise => await pool.execute(data, name, transferList) ) } + if (!fastify.hasDecorator('listTaskFunctions')) { + fastify.decorate('listTaskFunctions', (): string[] => + pool.listTaskFunctions() + ) + } done() } diff --git a/examples/typescript/websocket-server-pool/ws-hybrid/package.json b/examples/typescript/websocket-server-pool/ws-hybrid/package.json index f6707eb2..74912738 100644 --- a/examples/typescript/websocket-server-pool/ws-hybrid/package.json +++ b/examples/typescript/websocket-server-pool/ws-hybrid/package.json @@ -19,7 +19,7 @@ "author": "", "license": "ISC", "dependencies": { - "poolifier": "^2.6.25", + "poolifier": "^2.6.26", "ws": "^8.13.0" }, "devDependencies": { diff --git a/examples/typescript/websocket-server-pool/ws-hybrid/pnpm-lock.yaml b/examples/typescript/websocket-server-pool/ws-hybrid/pnpm-lock.yaml index 5e00a095..caa1d26c 100644 --- a/examples/typescript/websocket-server-pool/ws-hybrid/pnpm-lock.yaml +++ b/examples/typescript/websocket-server-pool/ws-hybrid/pnpm-lock.yaml @@ -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 diff --git a/examples/typescript/websocket-server-pool/ws-hybrid/src/websocket-server-worker.ts b/examples/typescript/websocket-server-pool/ws-hybrid/src/websocket-server-worker.ts index f495a721..0a1cbdfd 100644 --- a/examples/typescript/websocket-server-pool/ws-hybrid/src/websocket-server-worker.ts +++ b/examples/typescript/websocket-server-pool/ws-hybrid/src/websocket-server-worker.ts @@ -93,7 +93,11 @@ ClusterWorkerResponse } public constructor () { - super(WebSocketServerWorker.startWebSocketServer) + super(WebSocketServerWorker.startWebSocketServer, { + killHandler: () => { + WebSocketServerWorker.wss.close() + } + }) } }