diff --git a/.vs/AACloudPlatform/v15/.suo b/.vs/AACloudPlatform/v15/.suo index 84e35d8ff..187fc7dd4 100644 Binary files a/.vs/AACloudPlatform/v15/.suo and b/.vs/AACloudPlatform/v15/.suo differ diff --git a/Azure File Storage.js b/Azure File Storage.js index ad6fe935a..aa71f918b 100644 --- a/Azure File Storage.js +++ b/Azure File Storage.js @@ -164,7 +164,7 @@ exports.newAzureFileStorage = function newAzureFileStorage(BOT) { logger.write("[ERROR] createTextFile -> onFileCreated -> result = " + JSON.stringify(result)); logger.write("[ERROR] createTextFile -> onFileCreated -> response = " + JSON.stringify(response)); - if (err.message.indexOf("The server is busy") > 0) { + if (err.message.indexOf("The server is busy") > 0 || err.code === 'ECONNRESET') { setTimeout(secondTry, 1000); @@ -236,7 +236,7 @@ exports.newAzureFileStorage = function newAzureFileStorage(BOT) { if (err) { - if (err.message.indexOf("The server is busy") > 0) { + if (err.message.indexOf("The server is busy") > 0 || err.code === 'ECONNRESET') { setTimeout(secondTry, 1000); @@ -259,7 +259,23 @@ exports.newAzureFileStorage = function newAzureFileStorage(BOT) { } } - if (err.code = "ParentNotFound") { + if (err.code === "ResourceNotFound") { + + /* This is how Azure tell us the file does not exist. */ + + let customErr = { + result: global.CUSTOM_FAIL_RESPONSE.result, + message: "File does not exist." + }; + + logger.write("[ERROR] getTextFile -> onFileReceived -> Custom Response -> message = " + customErr.message); + + callBackFunction(customErr); + return; + + } + + if (err.code === "ParentNotFound") { /* This is how Azure tell us the folder where the file was supposed to be does not exist. We map this to our own response. */ @@ -274,7 +290,7 @@ exports.newAzureFileStorage = function newAzureFileStorage(BOT) { return; } - + logger.write("[ERROR] getTextFile -> onFileReceived -> Dont know what to do here. Cancelling operation. "); callBackFunction(global.DEFAULT_FAIL_RESPONSE); diff --git a/Indicator Bot Main Loop.js b/Indicator Bot Main Loop.js index da500c4b3..8dc5bf631 100644 --- a/Indicator Bot Main Loop.js +++ b/Indicator Bot Main Loop.js @@ -63,47 +63,11 @@ /* We will prepare first the infraestructure needed for the bot to run. There are 3 modules we need to sucessfullly initialize first. */ - let statusReport; let userBot; let nextWaitTime; - initializeStatusReport(); - - function initializeStatusReport() { - - if (FULL_LOG === true) { logger.write("[INFO] run -> loop -> initializeStatusReport -> Entering function."); } - - statusReport = STATUS_REPORT.newStatusReport(bot, DEBUG_MODULE, FILE_STORAGE, UTILITIES); - statusReport.initialize(bot, onInizialized); - - function onInizialized(err) { - - switch (err.result) { - case global.DEFAULT_OK_RESPONSE.result: { - logger.write("[INFO] run -> loop -> initializeStatusReport -> onInizialized > Execution finished well. :-)"); - initializeUserBot(); - return; - } - case global.DEFAULT_RETRY_RESPONSE.result: { // Something bad happened, but if we retry in a while it might go through the next time. - logger.write("[ERROR] run -> loop -> initializeStatusReport -> onInizialized > Retry Later. Requesting Execution Retry."); - nextWaitTime = 'Retry'; - loopControl(nextWaitTime); - return; - } - case global.DEFAULT_FAIL_RESPONSE.result: { // This is an unexpected exception that we do not know how to handle. - logger.write("[ERROR] run -> loop -> initializeStatusReport -> onInizialized > Operation Failed. Aborting the process."); - callBackFunction(err); - return; - } - case global.CUSTOM_FAIL_RESPONSE.result: { - logger.write("[INFO] run -> loop -> initializeStatusReport -> onInizialized > Execution finished with some expected issue."); - initializeUserBot(); - return; - } - } - } - } + initializeUserBot(); function initializeUserBot() { diff --git a/Run.js b/Run.js index 5b639de7f..923e3625b 100644 --- a/Run.js +++ b/Run.js @@ -131,6 +131,10 @@ global.dailyFilePeriods = global.dailyFilePeriods = JSON.parse(global.dailyFilePeriods); +/* File Path Root */ + +global.FILE_PATH_ROOT = 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; + /* Some LAGACY code starts here. Pending for clean up. */ const INTERVAL_EXECUTOR_MODULE = require('./Interval Executor'); diff --git a/Status Report.js b/Status Report.js index 32114cbc9..f577ca3a7 100644 --- a/Status Report.js +++ b/Status Report.js @@ -117,7 +117,7 @@ if (FULL_LOG === true) { logger.write("[INFO] initialize -> getFile -> Entering function."); } let fileName = "Status.Report.json" - let filePath = ownerBot.devTeam + "/" + ownerBot.codeName + "." + ownerBot.version.major + "." + ownerBot.version.minor + "/" + ownerBot.dataSetVersion + "/Processes/" + ownerBot.process + "/" + global.PLATFORM_CONFIG.codeName + "." + global.PLATFORM_CONFIG.version.major + "." + global.PLATFORM_CONFIG.version.minor; + let filePath = global.FILE_PATH_ROOT + "/Reports/" + bot.process; if (FULL_LOG === true) { logger.write("[INFO] initialize -> getFile -> fileName = " + fileName); } if (FULL_LOG === true) { logger.write("[INFO] initialize -> getFile -> filePath = " + filePath); } @@ -131,7 +131,7 @@ /* In this case we can assume that this is the first execution ever of this bot.*/ - thisObject.statusReport = JSON.parse('{}'); + thisObject.file = JSON.parse('{}'); let customErr = { result: global.CUSTOM_FAIL_RESPONSE.result, @@ -154,7 +154,7 @@ try { - thisObject.statusReport = JSON.parse(text); + thisObject.file = JSON.parse(text); callBack(global.DEFAULT_OK_RESPONSE); } catch (err) { @@ -202,7 +202,7 @@ } let fileName = "Status.Report.json" - let filePath = bot.devTeam + "/" + bot.codeName + "." + bot.version.major + "." + bot.version.minor + "/" + bot.dataSetVersion + "/Processes/" + bot.process + "/" + global.PLATFORM_CONFIG.codeName + "." + global.PLATFORM_CONFIG.version.major + "." + global.PLATFORM_CONFIG.version.minor; + let filePath = global.FILE_PATH_ROOT + "/Reports/" + bot.process; if (FULL_LOG === true) { logger.write("[INFO] save -> fileName = " + fileName); } if (FULL_LOG === true) { logger.write("[INFO] save -> filePath = " + filePath); } @@ -221,7 +221,7 @@ return; } - let fileContent = JSON.stringify(thisObject.statusReport); + let fileContent = JSON.stringify(thisObject.file); cloudStorage.createTextFile(filePath, fileName, fileContent + '\n', onFileCreated);