fix(validator): corrections to no leak like crazy
This commit is contained in:
@@ -7,15 +7,17 @@ import path, { dirname, join } from "path";
|
||||
import { fileURLToPath } from "url";
|
||||
import { db } from "./pkg/db/db.js";
|
||||
import { settings, type Setting } from "./pkg/db/schema/settings.js";
|
||||
import { env } from "./pkg/utils/envValidator.js";
|
||||
import { validateEnv } from "./pkg/utils/envValidator.js";
|
||||
import { createLogger } from "./pkg/logger/logger.js";
|
||||
import { returnFunc } from "./pkg/utils/return.js";
|
||||
import { initializeProdPool } from "./pkg/prodSql/prodSqlConnect.js";
|
||||
import { closePool, initializeProdPool } from "./pkg/prodSql/prodSqlConnect.js";
|
||||
import { tryCatch } from "./pkg/utils/tryCatch.js";
|
||||
|
||||
const PORT = Number(env.VITE_PORT) || 4200;
|
||||
import os, { hostname } from "os";
|
||||
import { sendNotify } from "./pkg/utils/notify.js";
|
||||
|
||||
const main = async () => {
|
||||
const env = validateEnv(process.env);
|
||||
const PORT = Number(env.VITE_PORT) || 4200;
|
||||
//create the logger
|
||||
const log = createLogger({ module: "system", subModule: "main start" });
|
||||
|
||||
@@ -94,28 +96,16 @@ const main = async () => {
|
||||
// start the server up
|
||||
server.listen(PORT, "0.0.0.0", () =>
|
||||
log.info(
|
||||
{ stack: { name: "test" } },
|
||||
`Server running in ${
|
||||
process.env.NODE_ENV ? process.env.NODE_ENV : "dev"
|
||||
}, on http://0.0.0.0:${PORT}${basePath}`
|
||||
)
|
||||
);
|
||||
|
||||
// Handle app exit signals
|
||||
process.on("SIGINT", async () => {
|
||||
console.log("\nGracefully shutting down...");
|
||||
//await closePool();
|
||||
process.exit(0);
|
||||
});
|
||||
|
||||
process.on("SIGTERM", async () => {
|
||||
console.log("Received termination signal, closing database...");
|
||||
//await closePool();
|
||||
process.exit(0);
|
||||
});
|
||||
|
||||
process.on("uncaughtException", async (err) => {
|
||||
console.log("Uncaught Exception:", err);
|
||||
//await closePool();
|
||||
//console.log("Uncaught Exception:", err);
|
||||
// await closePool();
|
||||
// const emailData = {
|
||||
// email: "blake.matthes@alpla.com", // should be moved to the db so it can be reused.
|
||||
// subject: `${os.hostname()} has just encountered a crash.`,
|
||||
@@ -126,15 +116,40 @@ const main = async () => {
|
||||
// },
|
||||
// };
|
||||
|
||||
// await sendEmail(emailData);
|
||||
if (!process.env.WEBHOOK_URL) {
|
||||
// await sendEmail(emailData);
|
||||
} else {
|
||||
await sendNotify({
|
||||
module: "system",
|
||||
subModule: "fatalCrash",
|
||||
hostname: os.hostname(),
|
||||
message: err.message,
|
||||
stack: err?.stack,
|
||||
});
|
||||
}
|
||||
|
||||
process.exit(1);
|
||||
});
|
||||
|
||||
process.on("beforeExit", async () => {
|
||||
console.log("Process is about to exit...");
|
||||
//await closePool();
|
||||
process.exit(0);
|
||||
});
|
||||
// setInterval(() => {
|
||||
// const used = process.memoryUsage();
|
||||
// console.log(
|
||||
// `Heap: ${(used.heapUsed / 1024 / 1024).toFixed(2)} MB / RSS: ${(
|
||||
// used.rss /
|
||||
// 1024 /
|
||||
// 1024
|
||||
// ).toFixed(2)} MB`
|
||||
// );
|
||||
// }, 10000);
|
||||
};
|
||||
|
||||
main();
|
||||
|
||||
// .catch((err) => {
|
||||
// const log = createLogger({ module: "system", subModule: "main" });
|
||||
// log.fatal(
|
||||
// { notify: true },
|
||||
// "There was a crash that occured and caused the app to restart."
|
||||
// );
|
||||
// process.exit(1);
|
||||
// });
|
||||
|
||||
Reference in New Issue
Block a user