diff --git a/.vs/AACloud/v15/.suo b/.vs/AACloud/v15/.suo index 45a534d97..30d409cfe 100644 Binary files a/.vs/AACloud/v15/.suo and b/.vs/AACloud/v15/.suo differ diff --git a/Debug Log.js b/Debug Log.js index 5720bf635..5d79870a5 100644 --- a/Debug Log.js +++ b/Debug Log.js @@ -65,7 +65,7 @@ /* We remove the folder in case it exister from before, so that all its content is gone. */ - rimraf.sync(folderToRemove); + //rimraf.sync(folderToRemove); /* We create the new one. */ @@ -137,7 +137,9 @@ } catch (err) { - console.log("Error trying to log info into a file. File: " + filePath + " Error:" + err.message); + console.log("Error trying to log info into a file."); + console.log("File: " + filePath ); + console.log("Error: " + err.message); } } diff --git a/Dependencies.js b/Dependencies.js index 3962056f6..bb746f4dd 100644 --- a/Dependencies.js +++ b/Dependencies.js @@ -8,7 +8,7 @@ let thisObject = { statusReports: new Map(), initialize: initialize, - key: [] + keys: [] }; /* @@ -125,7 +125,7 @@ key = pDependenciesConfig[i].devTeam + "-" + pDependenciesConfig[i].bot + "-" + pDependenciesConfig[i].process + "-" + pDependenciesConfig[i].dataSetVersion; } - thisObject.key.push(key); + thisObject.keys.push(key); thisObject.statusReports.set(key, statusReportModule); if (FULL_LOG === true) { logger.write("[INFO] initialize -> addReport -> Report added to Map. -> key = " + key); } diff --git a/Extraction Bot Main Loop.js b/Extraction Bot Main Loop.js index 819c5361e..69323a8bf 100644 --- a/Extraction Bot Main Loop.js +++ b/Extraction Bot Main Loop.js @@ -200,6 +200,12 @@ callBackFunction(global.DEFAULT_OK_RESPONSE); return; } + case "Too far in the future.": { + logger.write("[WARN] run -> loop -> startUserBot -> onFinished > Too far in the future. This Loop will enter in coma."); + nextWaitTime = 'Coma'; + loopControl(nextWaitTime); + return; + } default: { logger.write("[ERROR] run -> loop -> startUserBot -> onFinished > Unhandled custom response received. -> err.message = " + err.message); callBackFunction(err); @@ -249,6 +255,11 @@ setTimeout(loop, processConfig.sleepWaitTime); } break; + case 'Coma': { + if (FULL_LOG === true) { logger.write("[INFO] run -> loopControl -> Restarting Loop in " + (processConfig.retryWaitTime / 3600000) + " hours."); } + setTimeout(loop, processConfig.comaWaitTime); + } + break; } } diff --git a/Indicator Bot Main Loop.js b/Indicator Bot Main Loop.js index cebe3fe43..13527bf7f 100644 --- a/Indicator Bot Main Loop.js +++ b/Indicator Bot Main Loop.js @@ -211,6 +211,11 @@ setTimeout(loop, processConfig.sleepWaitTime); } break; + case 'Coma': { + if (FULL_LOG === true) { logger.write("[INFO] run -> loopControl -> Restarting Loop in " + (processConfig.retryWaitTime / 3600000) + " hours."); } + setTimeout(loop, processConfig.comaWaitTime); + } + break; } } diff --git a/Run.js b/Run.js index 11924c8c1..b436e6dd0 100644 --- a/Run.js +++ b/Run.js @@ -176,8 +176,6 @@ for (let p = 0; p < global.PLATFORM_CONFIG.executionList.length; p++) { botConfig.filePathRoot = botConfig.devTeam + "/" + botConfig.codeName + "." + botConfig.version.major + "." + botConfig.version.minor + "/" + global.PLATFORM_CONFIG.codeName + "." + global.PLATFORM_CONFIG.version.major + "." + global.PLATFORM_CONFIG.version.minor + "/" + global.EXCHANGE_NAME + "/" + botConfig.dataSetVersion; - let botId = botConfig.devTeam + "." + botConfig.codeName + "." + botConfig.process; - if (FULL_LOG === true) { logger.write("[INFO] run -> listItem.process = " + listItem.process); } /* 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. */ @@ -210,6 +208,10 @@ for (let p = 0; p < global.PLATFORM_CONFIG.executionList.length; p++) { year: pad(year, 4) }; + let padMonth = pad(month,2) + + let newInstanceBotConfig = JSON.parse(JSON.stringify(botConfig)); + let timeDelay = Math.random() * 10 * 1000; // We introduce a short delay so as to not overload the machine. setTimeout(startProcess, timeDelay); @@ -219,11 +221,11 @@ for (let p = 0; p < global.PLATFORM_CONFIG.executionList.length; p++) { switch (botConfig.type) { case 'Extraction': { - runExtractionBot(processConfig, month, year); + runExtractionBot(newInstanceBotConfig, processConfig, padMonth, year); break; } case 'Indicator': { - runIndicatorBot(processConfig, month, year); + runIndicatorBot(newInstanceBotConfig, processConfig, padMonth, year); break; } default: { @@ -255,11 +257,11 @@ for (let p = 0; p < global.PLATFORM_CONFIG.executionList.length; p++) { switch (botConfig.type) { case 'Extraction': { - runExtractionBot(processConfig, month, year); + runExtractionBot(botConfig, processConfig, month, year); break; } case 'Indicator': { - runIndicatorBot(processConfig, month, year); + runIndicatorBot(botConfig, processConfig, month, year); break; } default: { @@ -276,15 +278,15 @@ for (let p = 0; p < global.PLATFORM_CONFIG.executionList.length; p++) { switch (botConfig.type) { case 'Extraction': { - runExtractionBot(processConfig, month, year); + runExtractionBot(botConfig, processConfig, month, year); break; } case 'Indicator': { - runIndicatorBot(processConfig, month, year); + runIndicatorBot(botConfig, processConfig, month, year); break; } case 'Trading': { - runTradingBot(processConfig); + runTradingBot(botConfig, processConfig); break; } } @@ -301,14 +303,14 @@ for (let p = 0; p < global.PLATFORM_CONFIG.executionList.length; p++) { logger.write("[ERROR] run -> Process listed at the configuration file of AACloud not found at the configuration file of the bot. -> listItem.process = " + listItem.process); } - function runExtractionBot(pProcessConfig, pMonth, pYear) { + function runExtractionBot(pBotConfig, pProcessConfig, pMonth, pYear) { try { if (FULL_LOG === true) { logger.write("[INFO] runExtractionBot -> Entering function."); } if (FULL_LOG === true) { logger.write("[INFO] runExtractionBot -> pMonth = " + pMonth); } if (FULL_LOG === true) { logger.write("[INFO] runExtractionBot -> pYear = " + pYear); } - let extractionBotMainLoop = EXTRACTION_BOT_MAIN_LOOP_MODULE.newExtractionBotMainLoop(botConfig); + let extractionBotMainLoop = EXTRACTION_BOT_MAIN_LOOP_MODULE.newExtractionBotMainLoop(pBotConfig); extractionBotMainLoop.initialize(listItem.botPath, pProcessConfig, onInitializeReady); function onInitializeReady(err) { @@ -319,6 +321,13 @@ for (let p = 0; p < global.PLATFORM_CONFIG.executionList.length; p++) { function whenRunFinishes(err) { + let botId; + if (pYear !== undefined) { + botId = pBotConfig.devTeam + "." + pBotConfig.codeName + "." + pBotConfig.process + "." + pYear + "." + pMonth; + } else { + botId = pBotConfig.devTeam + "." + pBotConfig.codeName + "." + pBotConfig.process; + } + if (err.result === global.DEFAULT_OK_RESPONSE.result) { logger.write("[INFO] runExtractionBot -> onInitializeReady -> whenStartFinishes -> Bot execution finished sucessfully. :-)"); @@ -346,14 +355,14 @@ for (let p = 0; p < global.PLATFORM_CONFIG.executionList.length; p++) { } } - function runIndicatorBot(pProcessConfig, pMonth, pYear) { + function runIndicatorBot(pBotConfig, pProcessConfig, pMonth, pYear) { try { if (FULL_LOG === true) { logger.write("[INFO] runIndicatorBot -> Entering function."); } if (FULL_LOG === true) { logger.write("[INFO] runIndicatorBot -> pMonth = " + pMonth); } if (FULL_LOG === true) { logger.write("[INFO] runIndicatorBot -> pYear = " + pYear); } - let indicatorBotMainLoop = INDICATOR_BOT_MAIN_LOOP_MODULE.newIndicatorBotMainLoop(botConfig); + let indicatorBotMainLoop = INDICATOR_BOT_MAIN_LOOP_MODULE.newIndicatorBotMainLoop(pBotConfig); indicatorBotMainLoop.initialize(listItem.botPath, pProcessConfig, onInitializeReady); function onInitializeReady(err) { @@ -364,6 +373,13 @@ for (let p = 0; p < global.PLATFORM_CONFIG.executionList.length; p++) { function whenRunFinishes(err) { + let botId; + if (pYear !== undefined) { + botId = pBotConfig.devTeam + "." + pBotConfig.codeName + "." + pBotConfig.process + "." + pYear + "." + pMonth; + } else { + botId = pBotConfig.devTeam + "." + pBotConfig.codeName + "." + pBotConfig.process; + } + if (err.result === global.DEFAULT_OK_RESPONSE.result) { logger.write("[INFO] runIndicatorBot -> onInitializeReady -> whenStartFinishes -> Bot execution finished sucessfully. :-)"); @@ -391,12 +407,12 @@ for (let p = 0; p < global.PLATFORM_CONFIG.executionList.length; p++) { } } - function runTradingBot(pProcessConfig) { + function runTradingBot(pBotConfig, pProcessConfig) { try { if (FULL_LOG === true) { logger.write("[INFO] runTradingBot -> Entering function."); } - let tradingBotMainLoop = TRADING_BOT_MAIN_LOOP_MODULE.newTradingBotMainLoop(botConfig); + let tradingBotMainLoop = TRADING_BOT_MAIN_LOOP_MODULE.newTradingBotMainLoop(pBotConfig); tradingBotMainLoop.initialize(listItem.botPath, pProcessConfig, onInitializeReady); function onInitializeReady(err) { @@ -407,6 +423,13 @@ for (let p = 0; p < global.PLATFORM_CONFIG.executionList.length; p++) { function whenRunFinishes(err) { + let botId; + if (pYear !== undefined) { + botId = pBotConfig.devTeam + "." + pBotConfig.codeName + "." + pBotConfig.process + "." + pYear + "." + pMonth; + } else { + botId = pBotConfig.devTeam + "." + pBotConfig.codeName + "." + pBotConfig.process; + } + if (err.result === global.DEFAULT_OK_RESPONSE.result) { logger.write("[INFO] runTradingBot -> onInitializeReady -> whenStartFinishes -> Bot execution finished sucessfully. :-)"); diff --git a/Trading Bot Main Loop.js b/Trading Bot Main Loop.js index 78b56dd6a..4c517e4bc 100644 --- a/Trading Bot Main Loop.js +++ b/Trading Bot Main Loop.js @@ -373,6 +373,11 @@ setTimeout(loop, processConfig.sleepWaitTime); } break; + case 'Coma': { + if (FULL_LOG === true) { logger.write("[INFO] run -> loopControl -> Restarting Loop in " + (processConfig.retryWaitTime / 3600000) + " hours."); } + setTimeout(loop, processConfig.comaWaitTime); + } + break; } }