From ebbe511497e46edec107db325a14cbaa8282cee6 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Thu, 15 Mar 2018 12:43:48 +0100 Subject: [PATCH] Finished with Olivia Multi Period Market moved to Alpha --- .vs/AACloudPlatform/v15/.suo | Bin 81920 -> 77824 bytes Azure File Storage.js | 24 ++++++++++++++++++---- Indicator Bot Main Loop.js | 38 +---------------------------------- Run.js | 4 ++++ Status Report.js | 10 ++++----- 5 files changed, 30 insertions(+), 46 deletions(-) diff --git a/.vs/AACloudPlatform/v15/.suo b/.vs/AACloudPlatform/v15/.suo index 84e35d8ff3628c3e28adee07ec8abb4689927a57..187fc7dd42dc36f65f16acca2ecba854d4cd1425 100644 GIT binary patch delta 3272 zcmd^>e{fXQ7036y>@L~-kSs}dL$km}LRfJVKp@FNNH!3uwm`FK#3-OiNGeN1e(i1{ zk+{pxU~Q4zgUM*E=$k1MQA^BaL@??GnNExRs_6*+2bAe_EQ6S7W{R}ge($n725Vc! znf4#=&gY$T@44^Z^Ugi@?hOQVfs5L`C7E|=G@1l37Kub4qI&w9u586n%Q>^E28U@D z`xHN&;87)#+K3)~B>QPJdM2&;p6SrEU@AxkR!{~oT;w0}fs%`QJ(p|et*}E&0yBUC zBm&uEBIGoX1EeQuka@rc7K16E0F;8+U=EneL)v+Ud!gL}@`J8y&eEl1!E&$y zxPY7@UaC<4A*coqfro*#t&Yh@As+*4fOMr6@^MfHCi7OEIkOvD8<1~pfc!CN4Z6~2 zc%ZZc`I;Bf2Yv!Jfz6-;JPkiXN|WJw!;0N9x0cU;GK9J%|Vy>K^fd^ zAdR}1+zy!uvViPtft&>H1JaqhA!h<3$N(l#0*@&f4}LMxKKDClkt539h0x~%8F<+y zi(CLHosbK`0=|(rJ6Mxu_yH=FU=@5b1fa-X>$%QQHlrz4lP$7rM7j!%8)IYgXaBo_r&`#ORzq&~rTOUt9>w!L_8I*t{qR9<6j?$kuNT`P^MOof>1#Bl zq02R!2jmJY0CF{oKrwItzLH|+G=ny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5g{8`Ko03V7PTB`%%+1*nt>rRvl(J@iw?8v6IC%fp?6NhDM6CpCUcim>?nakRT9nRaz8 zH&||W#IIT5_hX!_biFAVl!P+_du+JoX12+92GZ_Ins2b%{0Z@wRd-=2u$O>={53%?`Db5r*G!T0 WdY0%^Q?8?)>OamnpOG#8DE 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);