diff --git a/DebugLog.js b/DebugLog.js index 07da825e5..d2f34a057 100644 --- a/DebugLog.js +++ b/DebugLog.js @@ -66,7 +66,13 @@ exports.newDebugLog = function newDebugLog() { const FILE_STORAGE = require('./FileStorage.js'); let fileStorage = FILE_STORAGE.newFileStorage(); - let filePath = thisObject.bot.filePathRoot + "/Logs/" + thisObject.bot.process + "/" + executionDatetime; + let filePath = thisObject.bot.filePathRoot + "/Logs/" + thisObject.bot.process + "/" + + if (thisObject.bot.SESSION !== undefined) { + filePath = filePath + thisObject.bot.SESSION.name + "/" + executionDatetime; + } else { + filePath = filePath + executionDatetime; + } if (thisObject.bot.debug.year !== undefined) { diff --git a/IndicatorBotProcessMainLoop.js b/IndicatorBotProcessMainLoop.js index 6eda2730c..717729ecb 100644 --- a/IndicatorBotProcessMainLoop.js +++ b/IndicatorBotProcessMainLoop.js @@ -178,8 +178,8 @@ return; } case global.DEFAULT_FAIL_RESPONSE.result: { // This is an unexpected exception that we do not know how to handle. + processStopped() logger.write(MODULE_NAME, "[ERROR] run -> loop -> initializeStatusDependencies -> onInizialized -> Operation Failed. Aborting the process."); - logger.persist(); clearInterval(fixedTimeLoopIntervalHandle); clearTimeout(nextLoopTimeoutHandle); @@ -282,6 +282,7 @@ return; } case global.DEFAULT_FAIL_RESPONSE.result: { // This is an unexpected exception that we do not know how to handle. + processStopped() logger.write(MODULE_NAME, "[ERROR] run -> loop -> initializeDataDependencies -> onInizialized -> Operation Failed. Aborting the process."); logger.persist(); clearInterval(fixedTimeLoopIntervalHandle); @@ -356,6 +357,7 @@ return; } case global.DEFAULT_FAIL_RESPONSE.result: { // This is an unexpected exception that we do not know how to handle. + processStopped() logger.write(MODULE_NAME, "[ERROR] run -> loop -> initializeUserBot -> onInizialized -> Operation Failed. Aborting the process."); logger.persist(); clearInterval(fixedTimeLoopIntervalHandle); @@ -456,6 +458,7 @@ return; } case global.DEFAULT_FAIL_RESPONSE.result: { // This is an unexpected exception that we do not know how to handle. + processStopped() logger.write(MODULE_NAME, "[ERROR] run -> loop -> startUserBot -> onFinished -> Operation Failed. Aborting the process."); logger.persist(); clearInterval(fixedTimeLoopIntervalHandle); @@ -585,6 +588,7 @@ return; } case global.DEFAULT_FAIL_RESPONSE.result: { // This is an unexpected exception that we do not know how to handle. + processStopped() logger.write(MODULE_NAME, "[ERROR] run -> loop -> intitializeProcessFramework -> onInizialized -> Operation Failed. Aborting the process."); logger.persist(); clearInterval(fixedTimeLoopIntervalHandle); @@ -687,6 +691,7 @@ return; } case global.DEFAULT_FAIL_RESPONSE.result: { // This is an unexpected exception that we do not know how to handle. + processStopped() logger.write(MODULE_NAME, "[ERROR] run -> loop -> startProcessFramework -> onFinished -> Operation Failed. Aborting the process."); logger.persist(); clearInterval(fixedTimeLoopIntervalHandle); @@ -932,6 +937,12 @@ } global.SYSTEM_EVENT_HANDLER.raiseEvent(key, 'Heartbeat', event) } + + function processStopped() { + let key = global.TASK_NODE.bot.processes[bot.processIndex].name + '-' + global.TASK_NODE.bot.processes[bot.processIndex].type + '-' + global.TASK_NODE.bot.processes[bot.processIndex].id + global.SYSTEM_EVENT_HANDLER.raiseEvent(key, 'Stopped') + } + } catch (err) { parentLogger.write(MODULE_NAME, "[ERROR] run -> err = "+ err.stack); clearInterval(fixedTimeLoopIntervalHandle); diff --git a/SensorBotProcessMainLoop.js b/SensorBotProcessMainLoop.js index 97b205f8d..d3f18e837 100644 --- a/SensorBotProcessMainLoop.js +++ b/SensorBotProcessMainLoop.js @@ -178,6 +178,7 @@ return; } case global.DEFAULT_FAIL_RESPONSE.result: { // This is an unexpected exception that we do not know how to handle. + processStopped() logger.write(MODULE_NAME, "[ERROR] run -> loop -> initializeStatusDependencies -> onInizialized -> Operation Failed. Aborting the process."); logger.persist(); clearInterval(fixedTimeLoopIntervalHandle); @@ -252,6 +253,7 @@ return; } case global.DEFAULT_FAIL_RESPONSE.result: { // This is an unexpected exception that we do not know how to handle. + processStopped() logger.write(MODULE_NAME, "[ERROR] run -> loop -> initializeExchangeAPI -> onInizialized -> Operation Failed. Aborting the process."); logger.persist(); clearInterval(fixedTimeLoopIntervalHandle); @@ -326,6 +328,7 @@ return; } case global.DEFAULT_FAIL_RESPONSE.result: { // This is an unexpected exception that we do not know how to handle. + processStopped() logger.write(MODULE_NAME, "[ERROR] run -> loop -> initializeUserBot -> onInizialized > Operation Failed. Aborting the process."); logger.persist(); clearInterval(fixedTimeLoopIntervalHandle); @@ -434,6 +437,7 @@ return; } case global.DEFAULT_FAIL_RESPONSE.result: { // This is an unexpected exception that we do not know how to handle. + processStopped() logger.write(MODULE_NAME, "[ERROR] run -> loop -> startUserBot -> onFinished > Operation Failed. Aborting the process."); logger.persist(); clearInterval(fixedTimeLoopIntervalHandle); @@ -705,6 +709,11 @@ } global.SYSTEM_EVENT_HANDLER.raiseEvent(key, 'Heartbeat', event) } + + function processStopped() { + let key = global.TASK_NODE.bot.processes[bot.processIndex].name + '-' + global.TASK_NODE.bot.processes[bot.processIndex].type + '-' + global.TASK_NODE.bot.processes[bot.processIndex].id + global.SYSTEM_EVENT_HANDLER.raiseEvent(key, 'Stopped') + } } catch (err) { diff --git a/Session.js b/Session.js index 135db5723..62f51a569 100644 --- a/Session.js +++ b/Session.js @@ -13,6 +13,11 @@ try { if (FULL_LOG === true) { parentLogger.write(MODULE_NAME, "[INFO] initialize -> Entering function."); } + /* Initialize this info so that everything is logged propeerly */ + bot.SESSION = { + name: bot.processNode.session.name + } + /* Check if there is a session */ if (bot.processNode.session === undefined) { parentLogger.write(MODULE_NAME, "[ERROR] initialize -> Cannot run without a Session."); diff --git a/TradingEngineProcessMainLoop.js b/TradingEngineProcessMainLoop.js index 43eb7bacf..f77c01b7a 100644 --- a/TradingEngineProcessMainLoop.js +++ b/TradingEngineProcessMainLoop.js @@ -212,8 +212,9 @@ return; } case global.DEFAULT_FAIL_RESPONSE.result: { // This is an unexpected exception that we do not know how to handle. + sessionStopped() + processStopped() logger.write(MODULE_NAME, "[ERROR] run -> loop -> initializeStatusDependencies -> onInizialized -> Operation Failed. Aborting the process."); - logger.persist(); clearInterval(fixedTimeLoopIntervalHandle); clearTimeout(nextLoopTimeoutHandle); @@ -287,6 +288,8 @@ return; } case global.DEFAULT_FAIL_RESPONSE.result: { // This is an unexpected exception that we do not know how to handle. + sessionStopped() + processStopped() logger.write(MODULE_NAME, "[ERROR] run -> loop -> initializeDataDependencies -> onInizialized -> Operation Failed. Aborting the process."); logger.persist(); clearInterval(fixedTimeLoopIntervalHandle); @@ -360,6 +363,8 @@ return; } case global.DEFAULT_FAIL_RESPONSE.result: { // This is an unexpected exception that we do not know how to handle. + sessionStopped() + processStopped() logger.write(MODULE_NAME, "[ERROR] run -> loop -> initializeContext -> onInizialized -> Operation Failed. Aborting the process."); logger.persist(); clearInterval(fixedTimeLoopIntervalHandle); @@ -434,6 +439,8 @@ return; } case global.DEFAULT_FAIL_RESPONSE.result: { // This is an unexpected exception that we do not know how to handle. + sessionStopped() + processStopped() logger.write(MODULE_NAME, "[ERROR] run -> loop -> initializeExchangeAPI -> onInizialized -> Operation Failed. Aborting the process."); logger.persist(); clearInterval(fixedTimeLoopIntervalHandle); @@ -541,6 +548,8 @@ return; } case global.DEFAULT_FAIL_RESPONSE.result: { // This is an unexpected exception that we do not know how to handle. + sessionStopped() + processStopped() logger.write(MODULE_NAME, "[ERROR] run -> loop -> initializeAssistant -> onInizialized -> Operation Failed. Aborting the process."); logger.persist(); clearInterval(fixedTimeLoopIntervalHandle); @@ -613,6 +622,8 @@ return; } case global.DEFAULT_FAIL_RESPONSE.result: { // This is an unexpected exception that we do not know how to handle. + sessionStopped() + processStopped() logger.write(MODULE_NAME, "[ERROR] run -> loop -> intitializeProcessFramework -> onInizialized -> Operation Failed. Aborting the process."); logger.persist(); clearInterval(fixedTimeLoopIntervalHandle); @@ -715,6 +726,8 @@ return; } case global.DEFAULT_FAIL_RESPONSE.result: { // This is an unexpected exception that we do not know how to handle. + sessionStopped() + processStopped() logger.write(MODULE_NAME, "[ERROR] run -> loop -> startProcessFramework -> onFinished -> Operation Failed. Aborting the process."); logger.persist(); clearInterval(fixedTimeLoopIntervalHandle); @@ -849,6 +862,8 @@ return; } case global.DEFAULT_FAIL_RESPONSE.result: { // This is an unexpected exception that we do not know how to handle. + sessionStopped() + processStopped() logger.write(MODULE_NAME, "[ERROR] run -> loop -> saveContext -> onFinished -> Operation Failed. Aborting the process."); logger.persist(); clearInterval(fixedTimeLoopIntervalHandle); @@ -1059,6 +1074,18 @@ } } + function processStopped() { + let key = global.TASK_NODE.bot.processes[bot.processIndex].name + '-' + global.TASK_NODE.bot.processes[bot.processIndex].type + '-' + global.TASK_NODE.bot.processes[bot.processIndex].id + global.SYSTEM_EVENT_HANDLER.raiseEvent(key, 'Stopped') + } + + function sessionStopped() { + if (bot.SESSION_STATUS === 'Running') { + global.SYSTEM_EVENT_HANDLER.raiseEvent(bot.sessionKey, 'Stopped') + bot.SESSION_STATUS = 'Stopped' + } + } + } catch (err) { parentLogger.write(MODULE_NAME, "[ERROR] run -> err = "+ err.stack); clearInterval(fixedTimeLoopIntervalHandle); diff --git a/server.js b/server.js index 3261fddf1..87cb567bd 100644 --- a/server.js +++ b/server.js @@ -28,14 +28,14 @@ global.CUSTOM_FAIL_RESPONSE = { /* Process Events */ process.on('uncaughtException', function (err) { - console.log('[INFO] Task Server -> server -> uncaughtException -> err.message = ' + err.message) - console.log('[INFO] Task Server -> server -> uncaughtException -> err.stack = ' + err.stack) + 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) }) process.on('unhandledRejection', (reason, p) => { - console.log('[INFO] Task Server -> server -> unhandledRejection -> reason = ' + JSON.stringify(reason)) - console.log('[INFO] Task Server -> server -> unhandledRejection -> p = ' + JSON.stringify(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) }) @@ -158,9 +158,9 @@ function bootLoader() { global.SYSTEM_EVENT_HANDLER.createEventHandler(key) global.SYSTEM_EVENT_HANDLER.raiseEvent(key, 'Running') // Meaning Task Running - global.HEARTBEAT_INTERVAL_HANDLER = setInterval(hearBeat, 1000) + global.HEARTBEAT_INTERVAL_HANDLER = setInterval(taskHearBeat, 1000) - function hearBeat() { + function taskHearBeat() { /* The heartbeat event is raised at the event handler of the instance of this task, created at the UI. */ let event = {