From 0e023f9a88de9dbf94a14e11df571ead4e3b45b7 Mon Sep 17 00:00:00 2001 From: Xc Date: Tue, 2 Dec 2025 10:54:22 +0800 Subject: [PATCH 1/4] 4.0.30-dev --- package.json | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index 602c8ba..2f4df11 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@xuchangzju/oak-cli", - "version": "4.0.29", + "version": "4.0.30", "description": "client for oak framework", "main": "lib/index.js", "scripts": { @@ -112,9 +112,9 @@ "lodash": "^4.17.21", "mini-css-extract-plugin": "^2.5.3", "node-watch": "^0.7.4", - "oak-backend-base": "^4.1.24", - "oak-domain": "^5.1.30", - "oak-frontend-base": "^5.3.43", + "oak-backend-base": "file:../oak-backend-base", + "oak-domain": "file:../oak-domain", + "oak-frontend-base": "file:../oak-frontend-base", "parse-asn1": "5.1.6", "postcss": "^8.4.4", "postcss-flexbugs-fixes": "^5.0.2", From 3781ed462988c0969044673ba279ffb18d7420b7 Mon Sep 17 00:00:00 2001 From: "QCQCQC@Debian" Date: Wed, 10 Dec 2025 10:13:58 +0800 Subject: [PATCH 2/4] =?UTF-8?q?feat:=20=E6=96=B0=E5=A2=9EstopRoutines?= =?UTF-8?q?=E7=9A=84=E6=89=A7=E8=A1=8C=EF=BC=8C=E5=9C=A8shutdown=E6=97=B6?= =?UTF-8?q?=E6=89=A7=E8=A1=8C=EF=BC=8C=E5=B9=B6=E5=AE=8C=E5=96=84=E4=BF=A1?= =?UTF-8?q?=E5=8F=B7=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/server/start.js | 26 ++++++++++++++++++++++---- lib/server/watch.js | 1 + lib/template.js | 2 +- package.json | 2 +- src/server/start.ts | 31 ++++++++++++++++++++++++++----- 5 files changed, 51 insertions(+), 11 deletions(-) diff --git a/lib/server/start.js b/lib/server/start.js index e6d9e6f..a4d5e99 100644 --- a/lib/server/start.js +++ b/lib/server/start.js @@ -402,15 +402,33 @@ async function startup(path, connector, omitWatchers, omitTimers, routine) { if (!omitTimers) { appLoader.startTimers(); } - process.on('SIGINT', async () => { - await appLoader.unmount(); - process.exit(0); - }); const shutdown = async () => { await httpServer.close(); await koa.removeAllListeners(); + await appLoader.execStopRoutines(); await appLoader.unmount(); (0, polyfill_1.removePolyfill)("startup"); }; + // 监听终止信号进行优雅关闭 + // SIGINT - Ctrl+C 发送的中断信号 + process.on('SIGINT', async () => { + await shutdown(); + process.exit(0); + }); + // SIGTERM - 系统/容器管理器发送的终止信号(Docker、K8s、PM2等) + process.on('SIGTERM', async () => { + await shutdown(); + process.exit(0); + }); + // SIGQUIT - Ctrl+\ 发送的退出信号 + process.on('SIGQUIT', async () => { + await shutdown(); + process.exit(0); + }); + // SIGHUP - 终端关闭时发送(可选) + process.on('SIGHUP', async () => { + await shutdown(); + process.exit(0); + }); return shutdown; } diff --git a/lib/server/watch.js b/lib/server/watch.js index 8019e88..c801260 100644 --- a/lib/server/watch.js +++ b/lib/server/watch.js @@ -499,6 +499,7 @@ const watch = async (projectPath, config) => { resolveFullPaths: true, }); function treatFile(filePath) { + console.log(`Processing file for alias replacement: ${filePath}`); const fileContents = fs_1.default.readFileSync(filePath, 'utf8'); const newContents = runFile({ fileContents, filePath }); // do stuff with newContents diff --git a/lib/template.js b/lib/template.js index cb0e8e3..b1d2bfc 100644 --- a/lib/template.js +++ b/lib/template.js @@ -424,7 +424,7 @@ function tsConfigPathsJsonContent(deps) { compilerOptions: { baseUrl: "./", paths, - typeRoots: ["./typings"] + typeRoots: ["./typings", "node_modules/@types"] } }, null, '\t'); } diff --git a/package.json b/package.json index 2f4df11..14aa130 100644 --- a/package.json +++ b/package.json @@ -44,7 +44,7 @@ "babel-plugin-module-resolver": "^5.0.0", "events": "^3.3.0", "fork-ts-checker-webpack-plugin": "^8.0.0", - "ts-node": "^10.9.1", + "ts-node": "^10.9.2", "typescript": "^5.2.2" }, "dependencies": { diff --git a/src/server/start.ts b/src/server/start.ts index 598ba37..63bbc38 100644 --- a/src/server/start.ts +++ b/src/server/start.ts @@ -492,18 +492,39 @@ export async function startup { - await appLoader.unmount(); - process.exit(0); - }); - const shutdown = async () => { await httpServer.close(); await koa.removeAllListeners(); + await appLoader.execStopRoutines(); await appLoader.unmount(); removePolyfill("startup"); } + // 监听终止信号进行优雅关闭 + // SIGINT - Ctrl+C 发送的中断信号 + process.on('SIGINT', async () => { + await shutdown(); + process.exit(0); + }); + + // SIGTERM - 系统/容器管理器发送的终止信号(Docker、K8s、PM2等) + process.on('SIGTERM', async () => { + await shutdown(); + process.exit(0); + }); + + // SIGQUIT - Ctrl+\ 发送的退出信号 + process.on('SIGQUIT', async () => { + await shutdown(); + process.exit(0); + }); + + // SIGHUP - 终端关闭时发送(可选) + process.on('SIGHUP', async () => { + await shutdown(); + process.exit(0); + }); + return shutdown } \ No newline at end of file From 3e0dba7172fb83f8761b99843e67f2441852aa3c Mon Sep 17 00:00:00 2001 From: "QCQCQC@Debian" Date: Wed, 10 Dec 2025 10:55:41 +0800 Subject: [PATCH 3/4] =?UTF-8?q?feat:=20=E4=BF=AE=E5=A4=8DstopRoutine?= =?UTF-8?q?=E9=87=8D=E5=A4=8D=E6=89=A7=E8=A1=8C=EF=BC=8C=E5=B9=B6=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0=E6=A8=A1=E6=9D=BF=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/server/start.js | 65 ++++++++++++++++++++++++--------- src/server/start.ts | 68 +++++++++++++++++++++++++---------- template/src/routines/stop.ts | 26 ++++++++++++++ 3 files changed, 124 insertions(+), 35 deletions(-) create mode 100644 template/src/routines/stop.ts diff --git a/lib/server/start.js b/lib/server/start.js index a4d5e99..555c73c 100644 --- a/lib/server/start.js +++ b/lib/server/start.js @@ -402,33 +402,64 @@ async function startup(path, connector, omitWatchers, omitTimers, routine) { if (!omitTimers) { appLoader.startTimers(); } + let isShutingdown = false; const shutdown = async () => { - await httpServer.close(); - await koa.removeAllListeners(); - await appLoader.execStopRoutines(); - await appLoader.unmount(); - (0, polyfill_1.removePolyfill)("startup"); + if (isShutingdown) { + return; + } + isShutingdown = true; + console.log('服务器正在关闭中...'); + try { + await httpServer.close(); + await koa.removeAllListeners(); + await appLoader.execStopRoutines(); + await appLoader.unmount(); + (0, polyfill_1.removePolyfill)("startup"); + } + catch (err) { + console.error('关闭服务器时出错:', err); + } + }; + // 处理优雅关闭的统一入口 + let shutdownStarted = false; + const handleShutdown = async (signal) => { + // 防止重复处理 + if (shutdownStarted) { + console.warn('关闭流程已启动,忽略此信号'); + return; + } + shutdownStarted = true; + console.log(`\n收到 ${signal} 信号,准备关闭服务器...`); + // 移除所有信号处理器,防止重复触发 + process.removeAllListeners('SIGINT'); + process.removeAllListeners('SIGTERM'); + process.removeAllListeners('SIGQUIT'); + process.removeAllListeners('SIGHUP'); + try { + await shutdown(); + process.exit(0); + } + catch (err) { + console.error('关闭过程出错:', err); + process.exit(1); + } }; // 监听终止信号进行优雅关闭 // SIGINT - Ctrl+C 发送的中断信号 - process.on('SIGINT', async () => { - await shutdown(); - process.exit(0); + process.on('SIGINT', () => { + handleShutdown('SIGINT'); }); // SIGTERM - 系统/容器管理器发送的终止信号(Docker、K8s、PM2等) - process.on('SIGTERM', async () => { - await shutdown(); - process.exit(0); + process.on('SIGTERM', () => { + handleShutdown('SIGTERM'); }); // SIGQUIT - Ctrl+\ 发送的退出信号 - process.on('SIGQUIT', async () => { - await shutdown(); - process.exit(0); + process.on('SIGQUIT', () => { + handleShutdown('SIGQUIT'); }); // SIGHUP - 终端关闭时发送(可选) - process.on('SIGHUP', async () => { - await shutdown(); - process.exit(0); + process.on('SIGHUP', () => { + handleShutdown('SIGHUP'); }); return shutdown; } diff --git a/src/server/start.ts b/src/server/start.ts index 63bbc38..4cb3992 100644 --- a/src/server/start.ts +++ b/src/server/start.ts @@ -492,38 +492,70 @@ export async function startup { - await httpServer.close(); - await koa.removeAllListeners(); - await appLoader.execStopRoutines(); - await appLoader.unmount(); - - removePolyfill("startup"); + if (isShutingdown) { + return; + } + isShutingdown = true; + console.log('服务器正在关闭中...'); + try { + await httpServer.close(); + await koa.removeAllListeners(); + await appLoader.execStopRoutines(); + await appLoader.unmount(); + removePolyfill("startup"); + } catch (err) { + console.error('关闭服务器时出错:', err); + } } + // 处理优雅关闭的统一入口 + let shutdownStarted = false; + const handleShutdown = async (signal: string) => { + // 防止重复处理 + if (shutdownStarted) { + console.warn('关闭流程已启动,忽略此信号'); + return; + } + shutdownStarted = true; + + console.log(`\n收到 ${signal} 信号,准备关闭服务器...`); + + // 移除所有信号处理器,防止重复触发 + process.removeAllListeners('SIGINT'); + process.removeAllListeners('SIGTERM'); + process.removeAllListeners('SIGQUIT'); + process.removeAllListeners('SIGHUP'); + + try { + await shutdown(); + process.exit(0); + } catch (err) { + console.error('关闭过程出错:', err); + process.exit(1); + } + }; + // 监听终止信号进行优雅关闭 // SIGINT - Ctrl+C 发送的中断信号 - process.on('SIGINT', async () => { - await shutdown(); - process.exit(0); + process.on('SIGINT', () => { + handleShutdown('SIGINT'); }); // SIGTERM - 系统/容器管理器发送的终止信号(Docker、K8s、PM2等) - process.on('SIGTERM', async () => { - await shutdown(); - process.exit(0); + process.on('SIGTERM', () => { + handleShutdown('SIGTERM'); }); // SIGQUIT - Ctrl+\ 发送的退出信号 - process.on('SIGQUIT', async () => { - await shutdown(); - process.exit(0); + process.on('SIGQUIT', () => { + handleShutdown('SIGQUIT'); }); // SIGHUP - 终端关闭时发送(可选) - process.on('SIGHUP', async () => { - await shutdown(); - process.exit(0); + process.on('SIGHUP', () => { + handleShutdown('SIGHUP'); }); return shutdown diff --git a/template/src/routines/stop.ts b/template/src/routines/stop.ts new file mode 100644 index 0000000..7e3ec01 --- /dev/null +++ b/template/src/routines/stop.ts @@ -0,0 +1,26 @@ +import { Routine } from 'oak-domain/lib/types/Timer'; +import { EntityDict } from '@oak-app-domain'; +import { BackendRuntimeContext } from '../context/BackendRuntimeContext'; + +// process.on('uncaughtException', (err) => { +// console.error(`Caught exception: ${err}`); +// // Optionally, you can exit the process or perform cleanup +// }); + +// process.on('unhandledRejection', (err) => { +// console.error(`Caught rejection: ${err}`); +// // Optionally, you can exit the process or perform cleanup +// }); + + +const stopRoutines: Array> = [ + { + name: '示例性routine_stop', + routine: async (context, env) => { + console.log('示例性routine执行,请在src/routine/stop.ts中关闭'); + return context.opResult; + }, + }, +]; + +export default stopRoutines; From 52b3ed8d9758c341e62170bfac4a2a39b519b2f4 Mon Sep 17 00:00:00 2001 From: Xc Date: Wed, 10 Dec 2025 18:09:48 +0800 Subject: [PATCH 4/4] 4.0.30-pub --- package.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index 14aa130..c6a87c3 100644 --- a/package.json +++ b/package.json @@ -112,9 +112,9 @@ "lodash": "^4.17.21", "mini-css-extract-plugin": "^2.5.3", "node-watch": "^0.7.4", - "oak-backend-base": "file:../oak-backend-base", - "oak-domain": "file:../oak-domain", - "oak-frontend-base": "file:../oak-frontend-base", + "oak-backend-base": "^4.1.25", + "oak-domain": "^5.1.31", + "oak-frontend-base": "^5.3.43", "parse-asn1": "5.1.6", "postcss": "^8.4.4", "postcss-flexbugs-fixes": "^5.0.2",