diff --git a/IndicatorBotProcessMainLoop.js b/IndicatorBotProcessMainLoop.js index 717729ecb..5d742c75e 100644 --- a/IndicatorBotProcessMainLoop.js +++ b/IndicatorBotProcessMainLoop.js @@ -119,7 +119,7 @@ if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] run -> loop -> Entering function."); } /* Loop Heartbeat sent to the UI */ - hearBeat() + processHearBeat() /* We define here all the modules that the rest of the infraestructure, including the bots themselves can consume. */ @@ -801,7 +801,7 @@ /* We show we reached the end of the loop. */ - hearBeat() + processHearBeat() /* Here we check if we must stop the loop gracefully. */ @@ -929,18 +929,15 @@ } } - function hearBeat() { - 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 - + function processHearBeat() { let event = { seconds: (new Date()).getSeconds() } - global.SYSTEM_EVENT_HANDLER.raiseEvent(key, 'Heartbeat', event) + global.SYSTEM_EVENT_HANDLER.raiseEvent(bot.processKey, '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') + global.SYSTEM_EVENT_HANDLER.raiseEvent(bot.processKey, 'Stopped') } } catch (err) { diff --git a/MultiPeriodDaily.js b/MultiPeriodDaily.js index 7b4d9f14d..f7732a42b 100644 --- a/MultiPeriodDaily.js +++ b/MultiPeriodDaily.js @@ -24,6 +24,8 @@ const FILE_STORAGE = require('./FileStorage.js'); let fileStorage = FILE_STORAGE.newFileStorage(logger); + let bootstrappingTheProcess = false + let processConfig; return thisObject; @@ -268,6 +270,13 @@ */ interExecutionMemoryArray = []; + /* + Also, we will remember that we are bootstrapping the process, this will allow us, to advanceTime if necesary. + It can happen that a process depends on data from another process that does not produce a file during the first day, or even more days, + in that situation we want the process not to just wait for that data that will never arrive, but to advance time until it finds valid data. + */ + + bootstrappingTheProcess = true for (let i = 0; i < global.dailyFilePeriods.length; i++) { let emptyObject = {}; @@ -449,7 +458,7 @@ if ((err.result === "Fail Because" && err.message === "File does not exist.") || err.code === 'The specified key does not exist.') { - logger.write(MODULE_NAME, "[ERROR] start -> processTimePeriods -> periodsLoopBody -> dependencyLoopBody -> getCurrentFile -> onFileReceived -> err = "+ err.stack); + logger.write(MODULE_NAME, "[ERROR] start -> processTimePeriods -> periodsLoopBody -> dependencyLoopBody -> getPreviousFile -> onFileReceived -> err = "+ err.stack); callBackFunction(global.DEFAULT_RETRY_RESPONSE); return; } @@ -504,6 +513,16 @@ if ((err.result === "Fail Because" && err.message === "File does not exist.") || err.code === 'The specified key does not exist.') { + if (bootstrappingTheProcess === true) { + /* + In the special situation where we are running this process for the first time (no status report found), + we will consider the possibility that a depanant process does not produce a file during the first day of the market, + or even more than one day. That is why we are going to advance time here. + */ + advanceTime() + return + } + logger.write(MODULE_NAME, "[ERROR] start -> processTimePeriods -> periodsLoopBody -> dependencyLoopBody -> getCurrentFile -> onFileReceived -> err = " + err.code); logger.write(MODULE_NAME, "[ERROR] start -> processTimePeriods -> periodsLoopBody -> dependencyLoopBody -> getCurrentFile -> onFileReceived -> filePath = " + filePath); logger.write(MODULE_NAME, "[ERROR] start -> processTimePeriods -> periodsLoopBody -> dependencyLoopBody -> getCurrentFile -> onFileReceived -> fileName = " + fileName); @@ -513,7 +532,7 @@ if (err.result !== global.DEFAULT_OK_RESPONSE.result) { - logger.write(MODULE_NAME, "[ERROR] start -> processTimePeriods -> periodsLoopBody -> dependencyLoopBody -> getCurrentFile -> onFileReceived -> err = " + err.code); + logger.write(MODULE_NAME, "[ERROR] start -> processTimePeriods -> periodsLoopBody -> dependencyLoopBody -> getCurrentFile -> Not OK -> onFileReceived -> err = " + err.code); callBackFunction(err); return; } @@ -527,7 +546,7 @@ } catch (err) { - logger.write(MODULE_NAME, "[ERROR] start -> processTimePeriods -> periodsLoopBody -> dependencyLoopBody -> getCurrentFile -> onFileReceived -> err = "+ err.stack); + logger.write(MODULE_NAME, "[ERROR] start -> processTimePeriods -> periodsLoopBody -> dependencyLoopBody -> getCurrentFile -> Catch Error -> onFileReceived -> err = "+ err.stack); callBackFunction(global.DEFAULT_FAIL_RESPONSE); } } diff --git a/Root.js b/Root.js index cc459e242..a6c16f8bf 100644 --- a/Root.js +++ b/Root.js @@ -184,6 +184,10 @@ botConfig.filePathRoot = botConfig.devTeam + "/" + botConfig.codeName + "." + botConfig.version.major + "." + botConfig.version.minor + "/" + global.CLONE_EXECUTOR.codeName + "." + global.CLONE_EXECUTOR.version + "/" + global.EXCHANGE_NAME + "/" + botConfig.dataSetVersion; + /* Process Key */ + + botConfig.processKey = global.TASK_NODE.bot.processes[processIndex].name + '-' + global.TASK_NODE.bot.processes[processIndex].type + '-' + global.TASK_NODE.bot.processes[processIndex].id + if (FULL_LOG === true) { console.log(logDisplace + "Root : [INFO] start -> findProcess -> filePathRoot = " + botConfig.filePathRoot); } /* Now we loop throug all the configured processes at each bots configuration until we find the one we are supposed to run at this Node.js process. */ diff --git a/SensorBotProcessMainLoop.js b/SensorBotProcessMainLoop.js index d3f18e837..b37e8a9ee 100644 --- a/SensorBotProcessMainLoop.js +++ b/SensorBotProcessMainLoop.js @@ -121,7 +121,7 @@ if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] run -> loop -> Entering function."); } /* Loop Heartbeat sent to the UI */ - hearBeat() + processHearBeat() /* We define here all the modules that the rest of the infraestructure, including the bots themselves can consume. */ @@ -547,7 +547,7 @@ /* We show we reached the end of the loop. */ - hearBeat() + processHearBeat() /* Here we check if we must stop the loop gracefully. */ @@ -701,18 +701,15 @@ } } - function hearBeat() { - 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 - + function processHearBeat() { let event = { seconds: (new Date()).getSeconds() } - global.SYSTEM_EVENT_HANDLER.raiseEvent(key, 'Heartbeat', event) + global.SYSTEM_EVENT_HANDLER.raiseEvent(bot.processKey, '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') + global.SYSTEM_EVENT_HANDLER.raiseEvent(bot.processKey, 'Stopped') } } diff --git a/TradingEngineProcessMainLoop.js b/TradingEngineProcessMainLoop.js index f77c01b7a..d6d7a6b8c 100644 --- a/TradingEngineProcessMainLoop.js +++ b/TradingEngineProcessMainLoop.js @@ -1054,12 +1054,10 @@ } function processHeartBeat() { - 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 - let event = { seconds: (new Date()).getSeconds() } - global.SYSTEM_EVENT_HANDLER.raiseEvent(key, 'Heartbeat', event) + global.SYSTEM_EVENT_HANDLER.raiseEvent(bot.processKey, 'Heartbeat', event) } function sessionHeartBeat(processingDate) { @@ -1075,8 +1073,7 @@ } 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') + global.SYSTEM_EVENT_HANDLER.raiseEvent(bot.processKey, 'Stopped') } function sessionStopped() {