From 32125b2d800a945303b4601ad5cd7f48a85e9ef2 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Wed, 10 Jun 2020 15:15:21 +0200 Subject: [PATCH] processError implemented --- Session.js | 32 ++++++++++++++++++++++++++++++++ StatusReport.js | 28 ++++++++++++++-------------- TradingBotProcessMainLoop.js | 23 +++-------------------- server.js | 10 ++++++++++ 4 files changed, 59 insertions(+), 34 deletions(-) diff --git a/Session.js b/Session.js index 088a4415a..49ba30f62 100644 --- a/Session.js +++ b/Session.js @@ -45,6 +45,12 @@ global.EVENT_SERVER_CLIENT.listenToEvent(bot.sessionKey, 'Run Session', undefined, bot.sessionKey, undefined, runSession) global.EVENT_SERVER_CLIENT.listenToEvent(bot.sessionKey, 'Stop Session', undefined, bot.sessionKey, undefined, stopSession) + /* Errors sent to the UI */ + bot.sessionError = sessionError + + /* Heartbeats sent to the UI */ + bot.sessionHeartBeat = sessionHeartBeat + callBackFunction(global.DEFAULT_OK_RESPONSE) return @@ -372,6 +378,32 @@ } } + function sessionHeartBeat(processingDate) { + let event = { + seconds: (new Date()).getSeconds(), + processingDate: processingDate + } + global.EVENT_SERVER_CLIENT.raiseEvent(bot.sessionKey, 'Heartbeat', event) + + if (global.STOP_TASK_GRACEFULLY === true) { + bot.STOP_SESSION = true + } + } + + function sessionError(node, errorMessage) { + let event = { + nodeName: node.name, + nodeType: node.type, + nodeId: node.id, + errorMessage: errorMessage + } + global.EVENT_SERVER_CLIENT.raiseEvent(bot.sessionKey, 'Error', 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 b9865452e..72fe4381d 100644 --- a/StatusReport.js +++ b/StatusReport.js @@ -48,47 +48,47 @@ /* Some very basic validations that we have all the information needed. */ if (statusDependencyNode.referenceParent === undefined) { - logger.write(MODULE_NAME, "[ERROR] initialize -> Status Dependency without Reference Parent. Status Dependency = " + JSON.stringify(statusDependencyNode)); - callBackFunction(global.DEFAULT_FAIL_RESPONSE); + validationFailed(statusDependencyNode, "Status Dependency without Reference Parent.") return } if (statusDependencyNode.referenceParent.parentNode === undefined) { - logger.write(MODULE_NAME, "[ERROR] initialize -> Status Report not attached to a Process Definition. Status Report = " + JSON.stringify(statusDependencyNode.referenceParent)); - callBackFunction(global.DEFAULT_FAIL_RESPONSE); + validationFailed(statusDependencyNode.referenceParent, "Status Report not attached to a Process Definition.") return } if (statusDependencyNode.referenceParent.parentNode.config.codeName === undefined) { - logger.write(MODULE_NAME, "[ERROR] initialize -> Process Definition witn no codeName defined. Process Definition = " + JSON.stringify(statusDependencyNode.referenceParent.parentNode)); - callBackFunction(global.DEFAULT_FAIL_RESPONSE); + validationFailed(statusDependencyNode.referenceParent.parentNode, "Process Definition witn no codeName defined.") return } if (statusDependencyNode.referenceParent.parentNode.parentNode === undefined) { - logger.write(MODULE_NAME, "[ERROR] initialize -> Process Definition not attached to a Bot. Process Definition = " + JSON.stringify(statusDependencyNode.referenceParent.parentNode)); - callBackFunction(global.DEFAULT_FAIL_RESPONSE); + validationFailed(statusDependencyNode.referenceParent.parentNode, "Process Definition not attached to a Bot.") return } if (statusDependencyNode.referenceParent.parentNode.parentNode.config.codeName === undefined) { - logger.write(MODULE_NAME, "[ERROR] initialize -> Bot witn no codeName defined. Bot = " + JSON.stringify(statusDependencyNode.referenceParent.parentNode.parentNode)); - callBackFunction(global.DEFAULT_FAIL_RESPONSE); + validationFailed(statusDependencyNode.referenceParent.parentNode.parentNode, "Bot with no codeName defined.") return } if (statusDependencyNode.referenceParent.parentNode.parentNode.parentNode === undefined) { - logger.write(MODULE_NAME, "[ERROR] initialize -> Bot not attached to a Data Mine. Bot = " + JSON.stringify(statusDependencyNode.referenceParent.parentNode.parentNode)); - callBackFunction(global.DEFAULT_FAIL_RESPONSE); + validationFailed(statusDependencyNode.referenceParent.parentNode.parentNode, "Bot not attached to a Data Mine.") return } if (statusDependencyNode.referenceParent.parentNode.parentNode.parentNode.config.codeName === undefined) { - logger.write(MODULE_NAME, "[ERROR] initialize -> Data Mine witn no codeName defined. Data Mine = " + JSON.stringify(statusDependencyNode.referenceParent.parentNode.parentNode.parentNode)); - callBackFunction(global.DEFAULT_FAIL_RESPONSE); + validationFailed(statusDependencyNode.referenceParent.parentNode.parentNode.parentNode, "Data Mine witn no codeName defined.") return } + function validationFailed(errorInNode, errorMessage) { + let nodeString = JSON.stringify(errorInNode) + logger.write(MODULE_NAME, "[ERROR] initialize -> " + errorMessage + ' -> nodeString = ' + nodeString) + bot.processError(errorInNode, errorMessage) + callBackFunction(global.DEFAULT_FAIL_RESPONSE); + } + /* Simplifying the access to basic info */ statusDependencyNode.bot = statusDependencyNode.referenceParent.parentNode.parentNode.config.codeName statusDependencyNode.process = statusDependencyNode.referenceParent.parentNode.config.codeName diff --git a/TradingBotProcessMainLoop.js b/TradingBotProcessMainLoop.js index 8b2d75d8b..c2dbd8deb 100644 --- a/TradingBotProcessMainLoop.js +++ b/TradingBotProcessMainLoop.js @@ -99,10 +99,9 @@ bot.STOP_SESSION = true; /* Errors sent to the UI */ - bot.sessionError = sessionError + bot.processError = processError /* Heartbeats sent to the UI */ - bot.sessionHeartBeat = sessionHeartBeat bot.processHeartBeat = processHeartBeat loop(); @@ -897,30 +896,14 @@ global.EVENT_SERVER_CLIENT.raiseEvent(bot.processKey, 'Heartbeat', event) } - function sessionHeartBeat(processingDate) { - let event = { - seconds: (new Date()).getSeconds(), - processingDate: processingDate - } - global.EVENT_SERVER_CLIENT.raiseEvent(bot.sessionKey, 'Heartbeat', event) - - if (global.STOP_TASK_GRACEFULLY === true) { - bot.STOP_SESSION = true - } - } - - function sessionError(node, errorMessage) { + function processError(node, errorMessage) { let event = { nodeName: node.name, nodeType: node.type, nodeId: node.id, errorMessage: errorMessage } - global.EVENT_SERVER_CLIENT.raiseEvent(bot.sessionKey, 'Error', event) - - if (global.STOP_TASK_GRACEFULLY === true) { - bot.STOP_SESSION = true - } + global.EVENT_SERVER_CLIENT.raiseEvent(bot.processKey, 'Error', event) } function processStopped() { diff --git a/server.js b/server.js index e2840cc6d..5b48bf2a8 100644 --- a/server.js +++ b/server.js @@ -197,6 +197,16 @@ function bootLoader() { global.EVENT_SERVER_CLIENT.raiseEvent(key, 'Heartbeat', event) } + global.taskError = function taskError(node, errorMessage) { + let event = { + nodeName: node.name, + nodeType: node.type, + nodeId: node.id, + errorMessage: errorMessage + } + global.EVENT_SERVER_CLIENT.raiseEvent(key, 'Error', event) + } + for (let processIndex = 0; processIndex < global.TASK_NODE.bot.processes.length; processIndex++) { let config = global.TASK_NODE.bot.processes[processIndex].config