feat: 新增stopRoutines的执行,在shutdown时执行,并完善信号处理
This commit is contained in:
parent
0e023f9a88
commit
3781ed4629
|
|
@ -402,15 +402,33 @@ async function startup(path, connector, omitWatchers, omitTimers, routine) {
|
||||||
if (!omitTimers) {
|
if (!omitTimers) {
|
||||||
appLoader.startTimers();
|
appLoader.startTimers();
|
||||||
}
|
}
|
||||||
process.on('SIGINT', async () => {
|
|
||||||
await appLoader.unmount();
|
|
||||||
process.exit(0);
|
|
||||||
});
|
|
||||||
const shutdown = async () => {
|
const shutdown = async () => {
|
||||||
await httpServer.close();
|
await httpServer.close();
|
||||||
await koa.removeAllListeners();
|
await koa.removeAllListeners();
|
||||||
|
await appLoader.execStopRoutines();
|
||||||
await appLoader.unmount();
|
await appLoader.unmount();
|
||||||
(0, polyfill_1.removePolyfill)("startup");
|
(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;
|
return shutdown;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -499,6 +499,7 @@ const watch = async (projectPath, config) => {
|
||||||
resolveFullPaths: true,
|
resolveFullPaths: true,
|
||||||
});
|
});
|
||||||
function treatFile(filePath) {
|
function treatFile(filePath) {
|
||||||
|
console.log(`Processing file for alias replacement: ${filePath}`);
|
||||||
const fileContents = fs_1.default.readFileSync(filePath, 'utf8');
|
const fileContents = fs_1.default.readFileSync(filePath, 'utf8');
|
||||||
const newContents = runFile({ fileContents, filePath });
|
const newContents = runFile({ fileContents, filePath });
|
||||||
// do stuff with newContents
|
// do stuff with newContents
|
||||||
|
|
|
||||||
|
|
@ -424,7 +424,7 @@ function tsConfigPathsJsonContent(deps) {
|
||||||
compilerOptions: {
|
compilerOptions: {
|
||||||
baseUrl: "./",
|
baseUrl: "./",
|
||||||
paths,
|
paths,
|
||||||
typeRoots: ["./typings"]
|
typeRoots: ["./typings", "node_modules/@types"]
|
||||||
}
|
}
|
||||||
}, null, '\t');
|
}, null, '\t');
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -44,7 +44,7 @@
|
||||||
"babel-plugin-module-resolver": "^5.0.0",
|
"babel-plugin-module-resolver": "^5.0.0",
|
||||||
"events": "^3.3.0",
|
"events": "^3.3.0",
|
||||||
"fork-ts-checker-webpack-plugin": "^8.0.0",
|
"fork-ts-checker-webpack-plugin": "^8.0.0",
|
||||||
"ts-node": "^10.9.1",
|
"ts-node": "^10.9.2",
|
||||||
"typescript": "^5.2.2"
|
"typescript": "^5.2.2"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
|
|
||||||
|
|
@ -492,18 +492,39 @@ export async function startup<ED extends EntityDict & BaseEntityDict, FrontCxt e
|
||||||
appLoader.startTimers();
|
appLoader.startTimers();
|
||||||
}
|
}
|
||||||
|
|
||||||
process.on('SIGINT', async () => {
|
|
||||||
await appLoader.unmount();
|
|
||||||
process.exit(0);
|
|
||||||
});
|
|
||||||
|
|
||||||
const shutdown = async () => {
|
const shutdown = async () => {
|
||||||
await httpServer.close();
|
await httpServer.close();
|
||||||
await koa.removeAllListeners();
|
await koa.removeAllListeners();
|
||||||
|
await appLoader.execStopRoutines();
|
||||||
await appLoader.unmount();
|
await appLoader.unmount();
|
||||||
|
|
||||||
removePolyfill("startup");
|
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
|
return shutdown
|
||||||
}
|
}
|
||||||
Loading…
Reference in New Issue