From aa6ea90bad9cd83a3b30f1acafbfb850555ac238 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Mon, 18 Mar 2019 21:41:27 +0100 Subject: [PATCH] Inter Process Memory Implemented --- MultiPeriodDaily.js | 28 ++++++++++++++++++++++++++-- MultiPeriodMarket.js | 8 +++++++- 2 files changed, 33 insertions(+), 3 deletions(-) diff --git a/MultiPeriodDaily.js b/MultiPeriodDaily.js index 0a8447ab6..d40f4952c 100644 --- a/MultiPeriodDaily.js +++ b/MultiPeriodDaily.js @@ -98,6 +98,8 @@ let previousDay; // Holds the date of the previous day relative to the processing date. let currentDay; // Holds the processing date. + let interExecutionMemoryArray; + getContextVariables(); function getContextVariables() { @@ -233,7 +235,7 @@ contextVariables.lastFile = new Date(thisReport.lastFile); - if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> getContextVariables -> thisReport.lastFile !== undefined"); } + interExecutionMemoryArray = thisReport.interExecutionMemoryArray; processTimePeriods(); return; @@ -251,6 +253,19 @@ if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> getContextVariables -> thisReport.lastFile === undefined"); } if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> getContextVariables -> contextVariables.lastFile = " + contextVariables.lastFile); } + /* + The first time the process is running is the right time to create the data structure that is going to be shared across different executions. + This data structure has one object per each timePeriod. + */ + + interExecutionMemoryArray = []; + + for (let i = 0; i < global.dailyFilePeriods.length; i++) + { + let emptyObject = {}; + interExecutionMemoryArray.push(emptyObject); + } + processTimePeriods(); return; } @@ -511,7 +526,15 @@ const timePeriod = global.dailyFilePeriods[n][0]; const outputPeriodLabel = global.dailyFilePeriods[n][1]; - usertBot.start(dataFiles, timePeriod, outputPeriodLabel, currentDay, contextVariables.dateBeginOfMarket, contextVariables.dateEndOfMarket, onBotFinished); + usertBot.start( + dataFiles, + timePeriod, + outputPeriodLabel, + currentDay, + contextVariables.dateBeginOfMarket, + contextVariables.dateEndOfMarket, + interExecutionMemoryArray[n], + onBotFinished); function onBotFinished(err) { @@ -688,6 +711,7 @@ thisReport.file.lastExecution = bot.currentDaytime; thisReport.file.lastFile = lastFileDate; + thisReport.file.interExecutionMemoryArray = interExecutionMemoryArray; thisReport.save(callBack); } diff --git a/MultiPeriodMarket.js b/MultiPeriodMarket.js index 4cda411fa..20ade8176 100644 --- a/MultiPeriodMarket.js +++ b/MultiPeriodMarket.js @@ -244,7 +244,13 @@ const timePeriod = global.marketFilesPeriods[n][0]; const outputPeriodLabel = global.marketFilesPeriods[n][1]; - usertBot.start(dataFiles, timePeriod, outputPeriodLabel, contextVariables.dateBeginOfMarket, contextVariables.dateEndOfMarket, onBotFinished); + usertBot.start( + dataFiles, + timePeriod, + outputPeriodLabel, + contextVariables.dateBeginOfMarket, + contextVariables.dateEndOfMarket, + onBotFinished); function onBotFinished(err) {