More to Globals
This commit is contained in:
1 parent
5d73304b6d
commit
cb61d888e1
2 files changed
+52
-51
No files matched your search
@@ -340,5 +340,57 @@ exports.newGlobals = function newGlobals() {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
global.FINALIZE_LOGGERS = function () {
|
||||
global.LOGGER_MAP.forEach(forEachLogger)
|
||||
|
||||
function forEachLogger(logger) {
|
||||
if (logger !== undefined) {
|
||||
logger.finalize()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
global.FINALIZE_SESSIONS = function () {
|
||||
global.SESSION_MAP.forEach(forEachSession)
|
||||
|
||||
function forEachSession(session) {
|
||||
global.EVENT_SERVER_CLIENT.raiseEvent(session, 'Stopped')
|
||||
}
|
||||
}
|
||||
|
||||
global.SHUTTING_DOWN_PROCESS = false
|
||||
|
||||
global.EXIT_NODE_PROCESS = function exitProcess() {
|
||||
|
||||
if (global.unexpectedError !== undefined) {
|
||||
global.taskError(undefined, "An unexpected error caused the Task to stop.")
|
||||
}
|
||||
|
||||
if (global.SHUTTING_DOWN_PROCESS === true) { return }
|
||||
global.SHUTTING_DOWN_PROCESS = true
|
||||
|
||||
/* Signal that all sessions are stopping. */
|
||||
global.FINALIZE_SESSIONS()
|
||||
|
||||
/* Cleaning Before Exiting. */
|
||||
clearInterval(global.HEARTBEAT_INTERVAL_HANDLER)
|
||||
|
||||
if (global.TASK_NODE !== undefined) {
|
||||
for (let i = 0; i < global.TASK_NODE.bot.processes.length; i++) {
|
||||
let config = global.TASK_NODE.bot.processes[i].config
|
||||
let process = global.TASK_NODE.bot.processes[i]
|
||||
|
||||
let key = process.name + '-' + process.type + '-' + process.id
|
||||
global.EVENT_SERVER_CLIENT.raiseEvent(key, 'Stopped') // Meaning Process Stopped
|
||||
}
|
||||
}
|
||||
|
||||
global.FINALIZE_LOGGERS()
|
||||
//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
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -16,24 +16,6 @@ process.on('unhandledRejection', (reason, p) => {
|
||||
global.EXIT_NODE_PROCESS()
|
||||
})
|
||||
|
||||
function finalizeLoggers() {
|
||||
global.LOGGER_MAP.forEach(forEachLogger)
|
||||
|
||||
function forEachLogger(logger) {
|
||||
if (logger !== undefined) {
|
||||
logger.finalize()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function finalizeSessions() {
|
||||
global.SESSION_MAP.forEach(forEachSession)
|
||||
|
||||
function forEachSession(session) {
|
||||
global.EVENT_SERVER_CLIENT.raiseEvent(session, 'Stopped')
|
||||
}
|
||||
}
|
||||
|
||||
process.on('exit', function (config) {
|
||||
|
||||
if (global.TASK_NODE !== undefined) {
|
||||
@@ -64,39 +46,6 @@ process.on('message', message => {
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
let shuttingDownProcess = false
|
||||
global.EXIT_NODE_PROCESS = function exitProcess() {
|
||||
|
||||
if (global.unexpectedError !== undefined) {
|
||||
global.taskError(undefined, "An unexpected error caused the Task to stop.")
|
||||
}
|
||||
|
||||
if (shuttingDownProcess === true) { return }
|
||||
shuttingDownProcess = true
|
||||
|
||||
/* Signal that all sessions are stopping. */
|
||||
finalizeSessions()
|
||||
|
||||
/* Cleaning Before Exiting. */
|
||||
clearInterval(global.HEARTBEAT_INTERVAL_HANDLER)
|
||||
|
||||
if (global.TASK_NODE !== undefined) {
|
||||
for (let i = 0; i < global.TASK_NODE.bot.processes.length; i++) {
|
||||
let config = global.TASK_NODE.bot.processes[i].config
|
||||
let process = global.TASK_NODE.bot.processes[i]
|
||||
|
||||
let key = process.name + '-' + process.type + '-' + process.id
|
||||
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
|
||||
}
|
||||
|
||||
require('dotenv').config();
|
||||
|
||||
global.WRITE_LOGS_TO_FILES = process.env.WRITE_LOGS_TO_FILES
|
||||
|
||||
Reference in new issue
Block a user