拆分快手轻量后端入口
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
import type { Server } from "node:http";
|
||||
|
||||
import { stopScheduledJobs } from "../services/scheduler/scheduler-service.js";
|
||||
import { logError, logInfo } from "../utils/logger.js";
|
||||
import type { StartupState } from "./state.js";
|
||||
|
||||
export function createKuaishouShutdownController(
|
||||
server: Server,
|
||||
startupState: StartupState
|
||||
) {
|
||||
let shutdownStarted = false;
|
||||
|
||||
async function shutdown(signal: string) {
|
||||
if (shutdownStarted) {
|
||||
return;
|
||||
}
|
||||
|
||||
shutdownStarted = true;
|
||||
startupState.phase = "shutting_down";
|
||||
logInfo("[shutdown:kuaishou]", `received ${signal}, closing HTTP server`);
|
||||
|
||||
stopScheduledJobs();
|
||||
|
||||
if (!server.listening) {
|
||||
return;
|
||||
}
|
||||
|
||||
await new Promise<void>((resolve) => {
|
||||
server.close((error) => {
|
||||
if (error) {
|
||||
logError("[shutdown:kuaishou]", "failed to close HTTP server", error);
|
||||
process.exitCode = 1;
|
||||
}
|
||||
|
||||
resolve();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
return {
|
||||
isShutdownStarted: () => shutdownStarted,
|
||||
shutdown,
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user