From bb68148d2464e52e4dd49f24dc7dea51aa80f4e2 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Fri, 22 Nov 2019 19:36:16 +0100 Subject: [PATCH] Several Bug Fixes --- Commons.js | 3 ++- IndicatorBot.js | 1 + ProcessExecutionEvents.js | 14 +++++++++--- StatusDependencies.js | 46 ++++++++++++++++++++++++++++++--------- StatusReport.js | 2 +- 5 files changed, 51 insertions(+), 15 deletions(-) diff --git a/Commons.js b/Commons.js index 7b5eda849..d9f61ce44 100644 --- a/Commons.js +++ b/Commons.js @@ -265,6 +265,7 @@ dataBuildingProcedure, variableName, timePeriod, + timePeriodLabel, resultsWithIrregularPeriods, interExecutionMemory, processingDailyFiles, @@ -384,7 +385,7 @@ To do that, the condition to be met is that this execution must include all candles of the current day. */ if (processingDailyFiles) { - if (lastRecord.current.end === lastInstantOfTheDay) { + if (lastRecord.current.end === lastInstantOfTheDay && yesterday.variable !== undefined) { interExecutionMemory.variable = JSON.parse(JSON.stringify(yesterday.variable)) } } diff --git a/IndicatorBot.js b/IndicatorBot.js index 46cb50b89..4c823887a 100644 --- a/IndicatorBot.js +++ b/IndicatorBot.js @@ -101,6 +101,7 @@ outputDatasetNode.referenceParent.parentNode.dataBuilding, singularVariableName, timePeriod, + timePeriodLabel, resultsWithIrregularPeriods, interExecutionMemory, processingDailyFiles, diff --git a/ProcessExecutionEvents.js b/ProcessExecutionEvents.js index 8ff8c2f54..fd04c2efc 100644 --- a/ProcessExecutionEvents.js +++ b/ProcessExecutionEvents.js @@ -78,7 +78,7 @@ /* This forces this process to wait until the process that this one depends on, emits its event signaling that the process execution has finished. */ - let extraCallerId = '' + let extraCallerId = '-' + Math.trunc(Math.random() * 10000) + '-' if (month) { extraCallerId = extraCallerId + '-' + month } if (year) { extraCallerId = extraCallerId + '-' + year } @@ -87,6 +87,10 @@ let subscriptionId + if (global.LOG_CONTROL[MODULE_NAME].logInfo === true) { logger.write(MODULE_NAME, "[INFO] start -> waitForDependantProcess -> started listening to Process Execution Finished. "); } + if (global.LOG_CONTROL[MODULE_NAME].logInfo === true) { logger.write(MODULE_NAME, "[INFO] start -> waitForDependantProcess -> key = " + key); } + if (global.LOG_CONTROL[MODULE_NAME].logInfo === true) { logger.write(MODULE_NAME, "[INFO] start -> waitForDependantProcess -> callerId = " + callerId); } + global.SYSTEM_EVENT_HANDLER.listenToEvent(key, 'Process Execution Finished', undefined, callerId, responseCallBack, eventsCallBack) function responseCallBack(message) { @@ -95,13 +99,17 @@ callBackFunction(global.DEFAULT_FAIL_RESPONSE); } else { subscriptionId = message.eventSubscriptionId + if (global.LOG_CONTROL[MODULE_NAME].logInfo === true) { logger.write(MODULE_NAME, "[INFO] start -> waitForDependantProcess -> subscriptionId = " + subscriptionId); } } } function eventsCallBack(message) { - if (global.LOG_CONTROL[MODULE_NAME].logInfo === true) { logger.write(MODULE_NAME, "[INFO] start -> waitForDependantProcess -> eventsCallBack -> Entering function."); } + if (global.LOG_CONTROL[MODULE_NAME].logInfo === true) { logger.write(MODULE_NAME, "[INFO] start -> eventsCallBack -> Entering function."); } + if (global.LOG_CONTROL[MODULE_NAME].logInfo === true) { logger.write(MODULE_NAME, "[INFO] start -> eventsCallBack -> message = " + JSON.stringify(message)); } /* We continue the normal flow after we learn the dependent process has finished its execution. */ + if (global.LOG_CONTROL[MODULE_NAME].logInfo === true) { logger.write(MODULE_NAME, "[INFO] start -> eventsCallBack -> stopListening to Process Execution Finished. "); } + if (global.LOG_CONTROL[MODULE_NAME].logInfo === true) { logger.write(MODULE_NAME, "[INFO] start -> eventsCallBack -> subscriptionId = " + subscriptionId); } global.SYSTEM_EVENT_HANDLER.stopListening(key, 'Process Execution Finished', subscriptionId) if (message.event.err.result === global.DEFAULT_OK_RESPONSE.result) { @@ -126,7 +134,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 " + datetimeForLogs); } + if (global.LOG_CONTROL[MODULE_NAME].logInfo === true) { logger.write(MODULE_NAME, "[INFO] start -> " + currentProcessKey + " Process Execution Started " + datetimeForLogs); } callBackFunction(global.DEFAULT_OK_RESPONSE); } diff --git a/StatusDependencies.js b/StatusDependencies.js index 95092e152..542e25eec 100644 --- a/StatusDependencies.js +++ b/StatusDependencies.js @@ -33,7 +33,7 @@ } } else { logger.write(MODULE_NAME, "[ERROR] initialize -> onInitilized -> It is not possible to not have process dependencies, which means not status dependencies."); - callBackFunction(global.DEFAULT_OK_RESPONSE) + callBackFunction(global.DEFAULT_FAIL_RESPONSE) return } @@ -41,13 +41,39 @@ let alreadyCalledBack = false; let loadCount = 0; - + let dependenciesToProcess = [] for (let i = 0; i < thisObject.nodeArray.length; i++) { + let statusDependency = { + dependency: thisObject.nodeArray[i], + month: pMonth, + year: pYear + } + + dependenciesToProcess.push(statusDependency) + + /* + For the special case that the statusDependency is a Self Reference AND this process is sliced in different + instances for each month, we will add the main self reference status report that is month/year independent. + */ + + if (statusDependency.dependency.code.mainUtility === "Self Reference" && pMonth !== undefined && pYear !== undefined) { + let mainDependency = { + dependency: thisObject.nodeArray[i], + month: undefined, + year: undefined + } + + dependenciesToProcess.push(mainDependency) + } + } + + for (let i = 0; i < dependenciesToProcess.length; i++) { let statusReportModule = STATUS_REPORT.newStatusReport(BOT, logger, UTILITIES); logger.write(MODULE_NAME, "[INFO] initialize -> onInitilized -> Initializing Status Report # " + (i + 1)); - statusReportModule.initialize(thisObject.nodeArray[i], pMonth, pYear, onInitilized); + let statusDependency = dependenciesToProcess[i] + statusReportModule.initialize(statusDependency.dependency, statusDependency.month, statusDependency.year, onInitilized); function onInitilized(err) { @@ -78,7 +104,7 @@ switch (err.message) { case global.DEFAULT_OK_RESPONSE.message: { - if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] initialize -> onLoad -> Execution finished well. -> Status Dependency = " + JSON.stringify(thisObject.nodeArray[i])) } + if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] initialize -> onLoad -> Execution finished well. -> Status Dependency = " + JSON.stringify(statusDependency.dependency)) } addReport(); return; @@ -86,7 +112,7 @@ case "Status Report was never created.": { logger.write(MODULE_NAME, "[WARN] initialize -> onLoad -> err = " + err.stack); - logger.write(MODULE_NAME, "[WARN] initialize -> onLoad -> Report Not Found. -> Status Dependency = " + JSON.stringify(thisObject.nodeArray[i])) + logger.write(MODULE_NAME, "[WARN] initialize -> onLoad -> Report Not Found. -> Status Dependency = " + JSON.stringify(statusDependency.dependency)) addReport(); return; @@ -95,7 +121,7 @@ case "Status Report is corrupt.": { logger.write(MODULE_NAME, "[WARN] initialize -> onLoad -> err = " + err.stack); - logger.write(MODULE_NAME, "[WARN] initialize -> onLoad -> Report Not Found. -> Status Dependency = " + JSON.stringify(thisObject.nodeArray[i])) + logger.write(MODULE_NAME, "[WARN] initialize -> onLoad -> Report Not Found. -> Status Dependency = " + JSON.stringify(statusDependency.dependency)) addReport(); return; @@ -128,10 +154,10 @@ let key; - if (thisObject.nodeArray[i].processRunMonthly === true) { - key = thisObject.nodeArray[i].devTeam + "-" + thisObject.nodeArray[i].bot + "-" + thisObject.nodeArray[i].process + "-" + thisObject.nodeArray[i].dataSetVersion + "-" + pYear + "-" + pMonth; + if (statusDependency.dependency.processRunMonthly === true && statusDependency.month !== undefined && statusDependency.year !== undefined) { + key = statusDependency.dependency.devTeam + "-" + statusDependency.dependency.bot + "-" + statusDependency.dependency.process + "-" + statusDependency.dependency.dataSetVersion + "-" + statusDependency.year + "-" + statusDependency.month; } else { - key = thisObject.nodeArray[i].devTeam + "-" + thisObject.nodeArray[i].bot + "-" + thisObject.nodeArray[i].process + "-" + thisObject.nodeArray[i].dataSetVersion; + key = statusDependency.dependency.devTeam + "-" + statusDependency.dependency.bot + "-" + statusDependency.dependency.process + "-" + statusDependency.dependency.dataSetVersion; } thisObject.keys.push(key); @@ -143,7 +169,7 @@ if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] initialize -> addReport -> Report added to Map. -> key = " + key); } - if (loadCount === thisObject.nodeArray.length) { + if (loadCount === dependenciesToProcess.length) { if (alreadyCalledBack === false) { alreadyCalledBack = true callBackFunction(global.DEFAULT_OK_RESPONSE); diff --git a/StatusReport.js b/StatusReport.js index b2e931a99..239f382b7 100644 --- a/StatusReport.js +++ b/StatusReport.js @@ -131,7 +131,7 @@ sessionPath = bot.SESSION.folderName + "/" } - if (statusDependencyNode.processRunMonthly === true) { + if (statusDependencyNode.processRunMonthly === true && month !== undefined && year !== undefined) { logger.fileName = MODULE_NAME + "." + statusDependencyNode.bot + "." + statusDependencyNode.process + "." + year + "." + month; timePath = "/" + year + "/" + month; }