39 lines
700 B
TypeScript
39 lines
700 B
TypeScript
import { closeInboundQueue } from "./queue";
|
|
import { startServer } from "./server";
|
|
|
|
const server = startServer();
|
|
|
|
async function shutdown(signal: string) {
|
|
console.log(`[omni_inbound] shutting down by ${signal}`);
|
|
|
|
try {
|
|
await new Promise<void>((resolve, reject) => {
|
|
server.close((error) => {
|
|
if (error) {
|
|
reject(error);
|
|
return;
|
|
}
|
|
resolve();
|
|
});
|
|
});
|
|
} catch {
|
|
// ignore shutdown errors
|
|
}
|
|
|
|
try {
|
|
await closeInboundQueue();
|
|
} catch {
|
|
// ignore shutdown errors
|
|
}
|
|
|
|
process.exit(0);
|
|
}
|
|
|
|
process.on("SIGINT", () => {
|
|
void shutdown("SIGINT");
|
|
});
|
|
|
|
process.on("SIGTERM", () => {
|
|
void shutdown("SIGTERM");
|
|
});
|