From ce1264dd3922d352cadc678575427e92129dcaeb Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Sat, 16 Nov 2019 11:08:27 +0100 Subject: [PATCH] Bug Fixes to make Trading Bots start again --- ProcessExecutionEvents.js | 13 +++++++++---- Root.js | 17 ++++++++++------- Session.js | 2 -- TradingBotProcessMainLoop.js | 2 +- server.js | 2 +- 5 files changed, 21 insertions(+), 15 deletions(-) diff --git a/ProcessExecutionEvents.js b/ProcessExecutionEvents.js index 47f131ab3..8ff8c2f54 100644 --- a/ProcessExecutionEvents.js +++ b/ProcessExecutionEvents.js @@ -22,6 +22,7 @@ let month; let year; let currentProcessKey + let datetimeForLogs = '' return thisObject; @@ -33,6 +34,10 @@ month = pMonth; year = pYear; + if (month && year) { + datetimeForLogs = "Month: " + month + " Year: " + year + } + let name = 'Not Depends on any Process' if (bot.processNode.referenceParent !== undefined) { @@ -48,7 +53,7 @@ if (processThisDependsOn.code.monthlyInstances === true) { logger.fileName = MODULE_NAME + "." + name + "." + year + "." + month; } - if (global.LOG_CONTROL[MODULE_NAME].logInfo === true) { logger.write(MODULE_NAME, "[INFO] initialize -> " + currentProcessKey + "Month: " + month + " Year: " + year + " depends on " + name); } + if (global.LOG_CONTROL[MODULE_NAME].logInfo === true) { logger.write(MODULE_NAME, "[INFO] initialize -> " + currentProcessKey + datetimeForLogs + " depends on " + name); } } } } @@ -107,7 +112,7 @@ global.SYSTEM_EVENT_HANDLER.createEventHandler(currentProcessKey, 'Process Execution Started') global.SYSTEM_EVENT_HANDLER.raiseEvent(currentProcessKey, 'Process Execution Started', event) - if (global.LOG_CONTROL[MODULE_NAME].logInfo === true) { logger.write(MODULE_NAME, "[INFO] start -> eventsCallBack -> " + currentProcessKey + " Process Execution Started because " + key + " Month: " + month + " Year: " + year + " Finished."); } + if (global.LOG_CONTROL[MODULE_NAME].logInfo === true) { logger.write(MODULE_NAME, "[INFO] start -> eventsCallBack -> " + currentProcessKey + " Process Execution Started because " + key + datetimeForLogs + " Finished."); } } callBackFunction(message.event.err); @@ -121,7 +126,7 @@ global.SYSTEM_EVENT_HANDLER.createEventHandler(currentProcessKey, 'Process Execution Started') global.SYSTEM_EVENT_HANDLER.raiseEvent(currentProcessKey, 'Process Execution Started', event) - if (global.LOG_CONTROL[MODULE_NAME].logInfo === true) { logger.write(MODULE_NAME, "[INFO] start -> waitForDependantProcess -> " + currentProcessKey + " Process Execution Started Month: " + month + " Year: " + year); } + if (global.LOG_CONTROL[MODULE_NAME].logInfo === true) { logger.write(MODULE_NAME, "[INFO] start -> waitForDependantProcess -> " + currentProcessKey + " Process Execution Started " + datetimeForLogs); } callBackFunction(global.DEFAULT_OK_RESPONSE); } @@ -144,7 +149,7 @@ global.SYSTEM_EVENT_HANDLER.createEventHandler(currentProcessKey, 'Process Execution Finished') global.SYSTEM_EVENT_HANDLER.raiseEvent(currentProcessKey, 'Process Execution Finished', event) - if (global.LOG_CONTROL[MODULE_NAME].logInfo === true) { logger.write(MODULE_NAME, "[INFO] finish -> " + currentProcessKey + " Process Execution Finished Month: " + month + " Year: " + year); } + if (global.LOG_CONTROL[MODULE_NAME].logInfo === true) { logger.write(MODULE_NAME, "[INFO] finish -> " + currentProcessKey + " Process Execution Finished " + datetimeForLogs); } callBackFunction(global.DEFAULT_OK_RESPONSE); diff --git a/Root.js b/Root.js index 263742304..bd73471d9 100644 --- a/Root.js +++ b/Root.js @@ -142,43 +142,46 @@ /* Some very basic validations that we have all the information needed. */ if (processInstance.referenceParent === undefined) { - logger.write(MODULE_NAME, "[ERROR] start-> Process Instance without Reference Parent. Process Instance = " + JSON.stringify(processInstance)); + console.log(logDisplace + "Root : [INFO] start -> Process Instance without Reference Parent. Process Instance = " + JSON.stringify(processInstance)); global.EXIT_NODE_PROCESS() return } if (processInstance.referenceParent.code.codeName === undefined) { - logger.write(MODULE_NAME, "[ERROR] start-> Process Definition witn no codeName defined. Process Definition = " + JSON.stringify(processInstance.referenceParent)); + console.log(logDisplace + "Root : [INFO] start -> Process Definition witn no codeName defined. Process Definition = " + JSON.stringify(processInstance.referenceParent)); global.EXIT_NODE_PROCESS() return } if (processInstance.referenceParent.parentNode === undefined) { - logger.write(MODULE_NAME, "[ERROR] start-> Process Definition not attached to a Bot Definition. Process Definition = " + JSON.stringify(processInstance.referenceParent)); + console.log(logDisplace + "Root : [INFO] start -> Process Definition not attached to a Bot Definition. Process Definition = " + JSON.stringify(processInstance.referenceParent)); global.EXIT_NODE_PROCESS() return } if (processInstance.referenceParent.parentNode.code.codeName === undefined) { - logger.write(MODULE_NAME, "[ERROR] start-> Bot Definition witn no codeName defined. Bot Definition = " + JSON.stringify(processInstance.referenceParent.parentNode)); + console.log(logDisplace + "Root : [INFO] start -> Bot Definition witn no codeName defined. Bot Definition = " + JSON.stringify(processInstance.referenceParent.parentNode)); global.EXIT_NODE_PROCESS() return } if (processInstance.referenceParent.parentNode.parentNode === undefined) { - logger.write(MODULE_NAME, "[ERROR] start-> Bot Definition not attached to a Team. Bot Definition = " + JSON.stringify(processInstance.referenceParent.parentNode)); + console.log(logDisplace + "Root : [INFO] start -> Bot Definition not attached to a Team. Bot Definition = " + JSON.stringify(processInstance.referenceParent.parentNode)); global.EXIT_NODE_PROCESS() return } if (processInstance.referenceParent.parentNode.parentNode.code.codeName === undefined) { - logger.write(MODULE_NAME, "[ERROR] start-> Team witn no codeName defined. Team = " + JSON.stringify(processInstance.referenceParent.parentNode.parentNode)); + console.log(logDisplace + "Root : [INFO] start -> Team witn no codeName defined. Team = " + JSON.stringify(processInstance.referenceParent.parentNode.parentNode)); global.EXIT_NODE_PROCESS() return } /* Here we will check if we need to load the configuration and code of the bot from a file or we will take that from the UI. */ - if (processInstance.referenceParent.code.framework !== undefined) { + if ( + processInstance.referenceParent.code.framework !== undefined && + (processInstance.referenceParent.code.framework.name === 'Multi-Period-Market' || processInstance.referenceParent.code.framework.name === 'Multi-Period-Daily') + ) { botConfig = processInstance.referenceParent.parentNode.code botConfig.definedByUI = true bootingBot(processIndex) diff --git a/Session.js b/Session.js index 9a34d5899..6c791f314 100644 --- a/Session.js +++ b/Session.js @@ -45,8 +45,6 @@ function runSession(message) { - console.log(message.event.definition) - /* We are going to run the Definition comming at the event. */ bot.DEFINITION = JSON.parse(message.event.definition) bot.SESSION = JSON.parse(message.event.session) diff --git a/TradingBotProcessMainLoop.js b/TradingBotProcessMainLoop.js index 0bd3e5899..cb321b0ca 100644 --- a/TradingBotProcessMainLoop.js +++ b/TradingBotProcessMainLoop.js @@ -204,7 +204,7 @@ processExecutionEvents = PROCESS_EXECUTION_EVENTS.newProcessExecutionEvents(bot, logger) - processExecutionEvents.initialize(pMonth, pYear, onInizialized); + processExecutionEvents.initialize(undefined, undefined, onInizialized); function onInizialized(err) { diff --git a/server.js b/server.js index 3de7dd0ca..5c371209c 100644 --- a/server.js +++ b/server.js @@ -131,7 +131,7 @@ function preLoader() { if (taskId !== undefined) { /* The Task Manager sent the info via a process argument. In this case we listen to an event with the Task Info that should be emitted at the UI */ try { - console.log('[Info] Task Server -> server -> preLoader -> Listening to starting event -> key = ' + 'Task Server - ' + taskId) + console.log('[INFO] Task Server -> server -> preLoader -> Listening to starting event -> key = ' + 'Task Server - ' + taskId) global.SYSTEM_EVENT_HANDLER.listenToEvent('Task Server - ' + taskId, 'Run Task', undefined, undefined, undefined, eventReceived) function eventReceived(message) { global.TASK_NODE = message