mirror of
https://github.com/ZeppelinBot/Zeppelin.git
synced 2025-03-15 05:41:51 +00:00
fix: clinic.js 0kb output files
Something in our signal handlers/code that touched signal handlers conflicted with clinic.js's signal handler code. With this commit, we don't touch signal handlers at all if DEBUG mode is enabled.
This commit is contained in:
parent
29a1161c05
commit
b60a7fb145
5 changed files with 45 additions and 30 deletions
|
@ -8,14 +8,14 @@
|
||||||
"watch-yaml-parse-test": "cross-env NODE_ENV=development tsc-watch --onSuccess \"node dist/backend/src/yamlParseTest.js\"",
|
"watch-yaml-parse-test": "cross-env NODE_ENV=development tsc-watch --onSuccess \"node dist/backend/src/yamlParseTest.js\"",
|
||||||
"build": "rimraf dist && tsc",
|
"build": "rimraf dist && tsc",
|
||||||
"start-bot-dev": "cross-env NODE_ENV=development node -r ./register-tsconfig-paths.js --unhandled-rejections=strict --enable-source-maps --stack-trace-limit=30 --inspect=0.0.0.0:9229 dist/backend/src/index.js",
|
"start-bot-dev": "cross-env NODE_ENV=development node -r ./register-tsconfig-paths.js --unhandled-rejections=strict --enable-source-maps --stack-trace-limit=30 --inspect=0.0.0.0:9229 dist/backend/src/index.js",
|
||||||
"start-bot-dev-debug": "NODE_ENV=development clinic heapprofiler --collect-only --dest .clinic-bot -- node -r ./register-tsconfig-paths.js --unhandled-rejections=strict --enable-source-maps --stack-trace-limit=30 --inspect=0.0.0.0:9229 dist/backend/src/index.js",
|
"start-bot-dev-debug": "NODE_ENV=development DEBUG=true clinic heapprofiler --collect-only --dest .clinic-bot -- node -r ./register-tsconfig-paths.js --unhandled-rejections=strict --enable-source-maps --stack-trace-limit=30 --inspect=0.0.0.0:9229 dist/backend/src/index.js",
|
||||||
"start-bot-prod": "cross-env NODE_ENV=production node -r ./register-tsconfig-paths.js --unhandled-rejections=strict --enable-source-maps --stack-trace-limit=30 dist/backend/src/index.js",
|
"start-bot-prod": "cross-env NODE_ENV=production node -r ./register-tsconfig-paths.js --unhandled-rejections=strict --enable-source-maps --stack-trace-limit=30 dist/backend/src/index.js",
|
||||||
"start-bot-prod-debug": "NODE_ENV=production clinic heapprofiler --collect-only --dest .clinic-bot -- node -r ./register-tsconfig-paths.js --unhandled-rejections=strict --enable-source-maps --stack-trace-limit=30 dist/backend/src/index.js",
|
"start-bot-prod-debug": "NODE_ENV=production DEBUG=true clinic heapprofiler --collect-only --dest .clinic-bot -- node -r ./register-tsconfig-paths.js --unhandled-rejections=strict --enable-source-maps --stack-trace-limit=30 dist/backend/src/index.js",
|
||||||
"watch-bot": "cross-env NODE_ENV=development tsc-watch --onSuccess \"npm run start-bot-dev\"",
|
"watch-bot": "cross-env NODE_ENV=development tsc-watch --onSuccess \"npm run start-bot-dev\"",
|
||||||
"start-api-dev": "cross-env NODE_ENV=development node -r ./register-tsconfig-paths.js --unhandled-rejections=strict --enable-source-maps --stack-trace-limit=30 --inspect=0.0.0.0:9239 dist/backend/src/api/index.js",
|
"start-api-dev": "cross-env NODE_ENV=development node -r ./register-tsconfig-paths.js --unhandled-rejections=strict --enable-source-maps --stack-trace-limit=30 --inspect=0.0.0.0:9239 dist/backend/src/api/index.js",
|
||||||
"start-api-dev-debug": "NODE_ENV=development clinic heapprofiler --collect-only --dest .clinic-api -- node -r ./register-tsconfig-paths.js --unhandled-rejections=strict --enable-source-maps --stack-trace-limit=30 --inspect=0.0.0.0:9239 dist/backend/src/api/index.js",
|
"start-api-dev-debug": "NODE_ENV=development DEBUG=true clinic heapprofiler --collect-only --dest .clinic-api -- node -r ./register-tsconfig-paths.js --unhandled-rejections=strict --enable-source-maps --stack-trace-limit=30 --inspect=0.0.0.0:9239 dist/backend/src/api/index.js",
|
||||||
"start-api-prod": "cross-env NODE_ENV=production node -r ./register-tsconfig-paths.js --unhandled-rejections=strict --enable-source-maps --stack-trace-limit=30 dist/backend/src/api/index.js",
|
"start-api-prod": "cross-env NODE_ENV=production node -r ./register-tsconfig-paths.js --unhandled-rejections=strict --enable-source-maps --stack-trace-limit=30 dist/backend/src/api/index.js",
|
||||||
"start-api-prod-debug": "NODE_ENV=production clinic heapprofiler --collect-only --dest .clinic-api -- node -r ./register-tsconfig-paths.js --unhandled-rejections=strict --enable-source-maps --stack-trace-limit=30 dist/backend/src/api/index.js",
|
"start-api-prod-debug": "NODE_ENV=production DEBUG=true clinic heapprofiler --collect-only --dest .clinic-api -- node -r ./register-tsconfig-paths.js --unhandled-rejections=strict --enable-source-maps --stack-trace-limit=30 dist/backend/src/api/index.js",
|
||||||
"watch-api": "cross-env NODE_ENV=development tsc-watch --onSuccess \"npm run start-api-dev\"",
|
"watch-api": "cross-env NODE_ENV=development tsc-watch --onSuccess \"npm run start-api-dev\"",
|
||||||
"typeorm": "node -r ./register-tsconfig-paths.js ./node_modules/typeorm/cli.js",
|
"typeorm": "node -r ./register-tsconfig-paths.js ./node_modules/typeorm/cli.js",
|
||||||
"migrate-prod": "cross-env NODE_ENV=production npm run typeorm -- migration:run",
|
"migrate-prod": "cross-env NODE_ENV=production npm run typeorm -- migration:run",
|
||||||
|
|
|
@ -50,6 +50,11 @@ const envType = z.object({
|
||||||
DB_USER: z.string().optional().default("zeppelin"),
|
DB_USER: z.string().optional().default("zeppelin"),
|
||||||
DB_PASSWORD: z.string().optional(), // Default is set to DOCKER_MYSQL_PASSWORD further below
|
DB_PASSWORD: z.string().optional(), // Default is set to DOCKER_MYSQL_PASSWORD further below
|
||||||
DB_DATABASE: z.string().optional().default("zeppelin"),
|
DB_DATABASE: z.string().optional().default("zeppelin"),
|
||||||
|
|
||||||
|
DEBUG: z
|
||||||
|
.string()
|
||||||
|
.optional()
|
||||||
|
.transform((str) => str === "true"),
|
||||||
});
|
});
|
||||||
|
|
||||||
let toValidate = { ...process.env };
|
let toValidate = { ...process.env };
|
||||||
|
|
|
@ -197,6 +197,10 @@ setInterval(() => {
|
||||||
avgCount = 0;
|
avgCount = 0;
|
||||||
}, 5 * 60 * 1000);
|
}, 5 * 60 * 1000);
|
||||||
|
|
||||||
|
if (env.DEBUG) {
|
||||||
|
logger.info("NOTE: Bot started in DEBUG mode");
|
||||||
|
}
|
||||||
|
|
||||||
logger.info("Connecting to database");
|
logger.info("Connecting to database");
|
||||||
connect().then(async (connection) => {
|
connect().then(async (connection) => {
|
||||||
const client = new Client({
|
const client = new Client({
|
||||||
|
@ -429,27 +433,30 @@ connect().then(async (connection) => {
|
||||||
logger.info("Logging in...");
|
logger.info("Logging in...");
|
||||||
await client.login(env.BOT_TOKEN);
|
await client.login(env.BOT_TOKEN);
|
||||||
|
|
||||||
let stopping = false;
|
// Don't intercept any signals in DEBUG mode: https://github.com/clinicjs/node-clinic/issues/444#issuecomment-1474997090
|
||||||
const cleanupAndStop = async (code) => {
|
if (!env.DEBUG) {
|
||||||
if (stopping) {
|
let stopping = false;
|
||||||
return;
|
const cleanupAndStop = async (code) => {
|
||||||
}
|
if (stopping) {
|
||||||
stopping = true;
|
return;
|
||||||
logger.info("Cleaning up before exit...");
|
}
|
||||||
// Force exit after 10sec
|
stopping = true;
|
||||||
setTimeout(() => process.exit(code), 10 * SECONDS);
|
logger.info("Cleaning up before exit...");
|
||||||
await bot.stop();
|
// Force exit after 10sec
|
||||||
await connection.close();
|
setTimeout(() => process.exit(code), 10 * SECONDS);
|
||||||
logger.info("Done! Exiting now.");
|
await bot.stop();
|
||||||
process.exit(code);
|
await connection.close();
|
||||||
};
|
logger.info("Done! Exiting now.");
|
||||||
process.on("beforeExit", () => cleanupAndStop(0));
|
process.exit(code);
|
||||||
process.on("SIGINT", () => {
|
};
|
||||||
logger.info("Received SIGINT, exiting...");
|
process.on("beforeExit", () => cleanupAndStop(0));
|
||||||
cleanupAndStop(0);
|
process.on("SIGINT", () => {
|
||||||
});
|
logger.info("Received SIGINT, exiting...");
|
||||||
process.on("SIGTERM", () => {
|
cleanupAndStop(0);
|
||||||
logger.info("Received SIGTERM, exiting...");
|
});
|
||||||
cleanupAndStop(0);
|
process.on("SIGTERM", () => {
|
||||||
});
|
logger.info("Received SIGTERM, exiting...");
|
||||||
|
cleanupAndStop(0);
|
||||||
|
});
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -6,5 +6,8 @@
|
||||||
* - This is imported as early as possible to avoid removing our own signal handlers
|
* - This is imported as early as possible to avoid removing our own signal handlers
|
||||||
*/
|
*/
|
||||||
import "threads";
|
import "threads";
|
||||||
process.removeAllListeners("SIGINT");
|
import { env } from "./env";
|
||||||
process.removeAllListeners("SIGTERM");
|
if (!env.DEBUG) {
|
||||||
|
process.removeAllListeners("SIGINT");
|
||||||
|
process.removeAllListeners("SIGTERM");
|
||||||
|
}
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
# Exec is used to forward signals: https://unix.stackexchange.com/a/196053
|
# Exec is used to forward signals: https://unix.stackexchange.com/a/196053
|
||||||
|
|
||||||
cd /zeppelin/backend
|
cd /zeppelin/backend
|
||||||
if [ -n "$DEBUG" ]; then
|
if [ "$DEBUG" == "true" ]; then
|
||||||
echo "DEBUG MODE: Starting bot container without starting the bot"
|
echo "DEBUG MODE: Starting bot container without starting the bot"
|
||||||
exec tail -f /dev/null
|
exec tail -f /dev/null
|
||||||
else
|
else
|
||||||
|
|
Loading…
Add table
Reference in a new issue