diff --git a/IndicatorBot.js b/IndicatorBot.js index df704b925..bbc8d1290 100644 --- a/IndicatorBot.js +++ b/IndicatorBot.js @@ -81,9 +81,6 @@ try { let fixedTimeLoopIntervalHandle; - /* Errors sent to the UI */ - bot.processError = processError - /* Heartbeats sent to the UI */ bot.processHeartBeat = processHeartBeat @@ -763,26 +760,9 @@ global.EVENT_SERVER_CLIENT.raiseEvent(bot.processKey, 'Heartbeat', event) } - function processError(node, errorMessage) { - let event - if (node !== undefined) { - event = { - nodeName: node.name, - nodeType: node.type, - nodeId: node.id, - errorMessage: errorMessage - } - } else { - event = { - errorMessage: errorMessage - } - } - global.EVENT_SERVER_CLIENT.raiseEvent(bot.processKey, 'Error', event) - } - function processStopped() { if (global.unexpectedError !== undefined) { - processError(undefined, "An unexpected error caused the Process to stop.") + global.PROCESS_ERROR(bot.processKey, undefined, "An unexpected error caused the Process to stop.") } else { global.EVENT_SERVER_CLIENT.raiseEvent(bot.processKey, 'Stopped') } diff --git a/SensorBot.js b/SensorBot.js index 78cec7d95..84a6d821a 100644 --- a/SensorBot.js +++ b/SensorBot.js @@ -85,9 +85,6 @@ try { let fixedTimeLoopIntervalHandle; - /* Errors sent to the UI */ - bot.processError = processError - /* Heartbeats sent to the UI */ bot.processHeartBeat = processHeartBeat @@ -571,26 +568,9 @@ global.EVENT_SERVER_CLIENT.raiseEvent(bot.processKey, 'Heartbeat', event) } - function processError(node, errorMessage) { - let event - if (node !== undefined) { - event = { - nodeName: node.name, - nodeType: node.type, - nodeId: node.id, - errorMessage: errorMessage - } - } else { - event = { - errorMessage: errorMessage - } - } - global.EVENT_SERVER_CLIENT.raiseEvent(bot.processKey, 'Error', event) - } - function processStopped() { if (global.unexpectedError !== undefined) { - processError(undefined, "An unexpected error caused the Process to stop.") + global.PROCESS_ERROR(bot.processKey, undefined, "An unexpected error caused the Process to stop.") } else { global.EVENT_SERVER_CLIENT.raiseEvent(bot.processKey, 'Stopped') } diff --git a/Session.js b/Session.js index 7ad26a9b2..211c38946 100644 --- a/Session.js +++ b/Session.js @@ -41,8 +41,10 @@ global.EVENT_SERVER_CLIENT.listenToEvent(bot.sessionKey, 'Run Session', undefined, bot.sessionKey, undefined, onSessionRan) global.EVENT_SERVER_CLIENT.listenToEvent(bot.sessionKey, 'Stop Session', undefined, bot.sessionKey, undefined, onSessionStopped) - /* Errors sent to the UI */ + /* Connect this here so that it is accesible from other places */ bot.sessionError = sessionError + bot.sessionWarning = sessionWarning + bot.sessionInfo = sessionInfo /* Heartbeats sent to the UI */ bot.sessionHeartBeat = sessionHeartBeat @@ -113,7 +115,7 @@ socialBotsModule.sendMessage(bot.SESSION.type + " '" + bot.SESSION.name + "' is stopping " + commandOrigin) socialBotsModule.finalize() bot.STOP_SESSION = true - sessionError(bot.SESSION, commandOrigin) + sessionInfo(bot.SESSION, commandOrigin) } function setUpAppSchema() { @@ -421,6 +423,48 @@ } } + function sessionWarning(node, warningMessage) { + let event + if (node !== undefined) { + event = { + nodeName: node.name, + nodeType: node.type, + nodeId: node.id, + warningMessage: warningMessage + } + } else { + event = { + warningMessage: warningMessage + } + } + global.EVENT_SERVER_CLIENT.raiseEvent(bot.sessionKey, 'Warning', event) + + if (global.STOP_TASK_GRACEFULLY === true) { + bot.STOP_SESSION = true + } + } + + function sessionInfo(node, infoMessage) { + let event + if (node !== undefined) { + event = { + nodeName: node.name, + nodeType: node.type, + nodeId: node.id, + infoMessage: infoMessage + } + } else { + event = { + infoMessage: infoMessage + } + } + global.EVENT_SERVER_CLIENT.raiseEvent(bot.sessionKey, 'Info', event) + + if (global.STOP_TASK_GRACEFULLY === true) { + bot.STOP_SESSION = true + } + } + } catch (err) { parentLogger.write(MODULE_NAME, "[ERROR] initialize -> err = " + err.stack); callBackFunction(global.DEFAULT_FAIL_RESPONSE); diff --git a/StatusReport.js b/StatusReport.js index b442e3aa9..50cf8c2a1 100644 --- a/StatusReport.js +++ b/StatusReport.js @@ -83,7 +83,7 @@ function validationFailed(errorInNode, errorMessage) { let nodeString = JSON.stringify(errorInNode) logger.write(MODULE_NAME, "[ERROR] initialize -> " + errorMessage + ' -> nodeString = ' + nodeString) - bot.processError(errorInNode, errorMessage) + bot.global.PROCESS_ERROR(bot.processKey, errorInNode, errorMessage) callBackFunction(global.DEFAULT_FAIL_RESPONSE); } diff --git a/TradingBot.js b/TradingBot.js index 6204a524a..4f1e65487 100644 --- a/TradingBot.js +++ b/TradingBot.js @@ -45,9 +45,6 @@ let fixedTimeLoopIntervalHandle; bot.STOP_SESSION = true; - /* Errors sent to the UI */ - bot.processError = processError - /* Heartbeats sent to the UI */ bot.processHeartBeat = processHeartBeat @@ -654,26 +651,9 @@ global.EVENT_SERVER_CLIENT.raiseEvent(bot.processKey, 'Heartbeat', event) } - function processError(node, errorMessage) { - let event - if (node !== undefined) { - event = { - nodeName: node.name, - nodeType: node.type, - nodeId: node.id, - errorMessage: errorMessage - } - } else { - event = { - errorMessage: errorMessage - } - } - global.EVENT_SERVER_CLIENT.raiseEvent(bot.processKey, 'Error', event) - } - function processStopped() { if (global.unexpectedError !== undefined) { - processError(undefined, "An unexpected error caused the Process to stop.") + global.PROCESS_ERROR(bot.processKey, undefined, "An unexpected error caused the Process to stop.") } else { global.EVENT_SERVER_CLIENT.raiseEvent(bot.processKey, 'Stopped') } diff --git a/server.js b/server.js index 2d0f3225f..f3473bda2 100644 --- a/server.js +++ b/server.js @@ -51,6 +51,57 @@ global.REMOVE_TIME = function (datetime) { return new Date(date.getUTCFullYear() + "-" + (date.getUTCMonth() + 1) + "-" + date.getUTCDate() + " " + "00:00" + GMT_SECONDS); } +global.PROCESS_ERROR = function (processKey, node, errorMessage) { + let event + if (node !== undefined) { + event = { + nodeName: node.name, + nodeType: node.type, + nodeId: node.id, + errorMessage: errorMessage + } + } else { + event = { + errorMessage: errorMessage + } + } + global.EVENT_SERVER_CLIENT.raiseEvent(processKey, 'Error', event) +} + +global.PROCESS_WARNING = function (processKey, node, warningMessage) { + let event + if (node !== undefined) { + event = { + nodeName: node.name, + nodeType: node.type, + nodeId: node.id, + warningMessage: warningMessage + } + } else { + event = { + warningMessage: warningMessage + } + } + global.EVENT_SERVER_CLIENT.raiseEvent(processKey, 'Warning', event) +} + +global.PROCESS_INFO = function (processKey, node, infoMessage) { + let event + if (node !== undefined) { + event = { + nodeName: node.name, + nodeType: node.type, + nodeId: node.id, + infoMessage: infoMessage + } + } else { + event = { + infoMessage: infoMessage + } + } + global.EVENT_SERVER_CLIENT.raiseEvent(processKey, 'Info', event) +} + 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)