Improved Handling of Loggers while process is shutting down
This commit is contained in:
1 parent
57685ff222
commit
d435c0e158
7 files changed
+41
-4
No files matched your search
@@ -26,19 +26,28 @@ global.CUSTOM_FAIL_RESPONSE = {
|
||||
};
|
||||
|
||||
const ONE_DAY_IN_MILISECONDS = 24 * 60 * 60 * 1000;
|
||||
global.LOGGER_MAP = new Map()
|
||||
|
||||
process.on('uncaughtException', function (err) {
|
||||
console.log('[ERROR] Task Server -> server -> uncaughtException -> err.message = ' + err.message)
|
||||
console.log('[ERROR] Task Server -> server -> uncaughtException -> err.stack = ' + err.stack)
|
||||
process.exit(1)
|
||||
global.EXIT_NODE_PROCESS()
|
||||
})
|
||||
|
||||
process.on('unhandledRejection', (reason, p) => {
|
||||
console.log('[ERROR] Task Server -> server -> unhandledRejection -> reason = ' + JSON.stringify(reason))
|
||||
console.log('[ERROR] Task Server -> server -> unhandledRejection -> p = ' + JSON.stringify(p))
|
||||
process.exit(1)
|
||||
global.EXIT_NODE_PROCESS()
|
||||
})
|
||||
|
||||
function finalizeLoggers() {
|
||||
global.LOGGER_MAP.forEach(forEachLogger)
|
||||
|
||||
function forEachLogger(logger) {
|
||||
logger.finalize()
|
||||
}
|
||||
}
|
||||
|
||||
process.on('exit', function (code) {
|
||||
|
||||
if (global.TASK_NODE !== undefined) {
|
||||
@@ -69,8 +78,13 @@ process.on('message', message => {
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
let shuttingDownProcess = false
|
||||
global.EXIT_NODE_PROCESS = function exitProcess() {
|
||||
|
||||
if (shuttingDownProcess === true) { return }
|
||||
shuttingDownProcess = true
|
||||
|
||||
/* Cleaning Before Exiting. */
|
||||
clearInterval(global.HEARTBEAT_INTERVAL_HANDLER)
|
||||
|
||||
@@ -82,6 +96,7 @@ global.EXIT_NODE_PROCESS = function exitProcess() {
|
||||
global.EVENT_SERVER_CLIENT.raiseEvent(key, 'Stopped') // Meaning Process Stopped
|
||||
}
|
||||
|
||||
finalizeLoggers()
|
||||
//console.log("[INFO] Task Server -> " + global.TASK_NODE.name + " -> EXIT_NODE_PROCESS -> Task Server will stop in 10 seconds.");
|
||||
|
||||
setTimeout(process.exit, 10000) // We will give 10 seconds to logs be written on file
|
||||
|
||||
Reference in new issue
Block a user