26 lines
645 B
TypeScript
26 lines
645 B
TypeScript
import { logger } from "./logger.js";
|
|
import { pool } from "./db.js";
|
|
import { startHealthServer } from "./health.js";
|
|
|
|
async function main(): Promise<void> {
|
|
logger.info("bot starting");
|
|
const health = startHealthServer();
|
|
|
|
const shutdown = async (signal: string): Promise<void> => {
|
|
logger.info({ signal }, "shutting down");
|
|
health.close();
|
|
await pool.end();
|
|
process.exit(0);
|
|
};
|
|
|
|
process.on("SIGINT", () => void shutdown("SIGINT"));
|
|
process.on("SIGTERM", () => void shutdown("SIGTERM"));
|
|
|
|
logger.info("bot ready");
|
|
}
|
|
|
|
main().catch((err) => {
|
|
logger.fatal({ err }, "bot failed to start");
|
|
process.exit(1);
|
|
});
|