feat: 新增stopRoutines的执行,在shutdown时执行,并完善信号处理

This commit is contained in:
QCQCQC@Debian 2025-12-10 10:13:58 +08:00
parent 0e023f9a88
commit 3781ed4629
5 changed files with 51 additions and 11 deletions

View File

@ -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;
}

View File

@ -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

View File

@ -424,7 +424,7 @@ function tsConfigPathsJsonContent(deps) {
compilerOptions: {
baseUrl: "./",
paths,
typeRoots: ["./typings"]
typeRoots: ["./typings", "node_modules/@types"]
}
}, null, '\t');
}

View File

@ -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": {

View File

@ -492,18 +492,39 @@ export async function startup<ED extends EntityDict & BaseEntityDict, FrontCxt e
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();
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
}