From de1762e3f277945d85cd65f7154efc7f7b86af32 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Sun, 29 Apr 2018 23:58:27 +0200 Subject: [PATCH] File Cache with Error Handling --- .vs/AAWeb/v15/.suo | Bin 66048 -> 66048 bytes Files/FileCache.js | 102 +++++++++++++++++++++++++-------------------- 2 files changed, 56 insertions(+), 46 deletions(-) diff --git a/.vs/AAWeb/v15/.suo b/.vs/AAWeb/v15/.suo index 7b7821b29a2b5dc765532310c3a5ad7eb5aa20b3..532e5d610b29e3d777e41a5d10b84fe4e0cd22a7 100644 GIT binary patch delta 424 zcmZo@VQFY#*^tA;+F;Ni!n(PT={Ga$hQ?KVKqecz1mmR5m2&@`89O&uCbb)KcZx7D z2s1D+a53~xE?f~mxo08gWZs1uljl##o_uoY5g={GJqfO6#^i~6v%um}!D^EYrdT1V zpSAha^uJ7#dza0f{BO3-Sk!jz{m&`1c6Kk6c>SYut9VHT`IO{3D;!BDW02sH*9B|TsWh7bKQm;ERzNH@J#-_ znR9aX&IyZIwy{hOSi6o_6k;BjjF|jqbMa)&-OmN3;i5_h(t&Kw&5C<&F|wxWWfkj9 z7F?k{xpQqPR;{;LON)y0izXY+HrQ-%AeL$Kq(dd_;t~vuObiUz4870D;+&YAvFHrb SA<_%gujhq#y~-=L1=>dF~>2Mir2iF8z!yRt7*=ZS3l1XlQ0=sq4bP$Ox1HflLRu zY6)Db7cJqMyl|%P6`9S8=pQ#SA46~;KZVJ{CW3y>?dS@zU@MizFr%$!O4mV$&QZDC=Q1}bu6oUFIh iV6)D-M5fIX50$b{_Sh+gq-D_=Ca8QY)8^g_#fAV3QI8b> diff --git a/Files/FileCache.js b/Files/FileCache.js index 791917f58..e5386b403 100644 --- a/Files/FileCache.js +++ b/Files/FileCache.js @@ -3,6 +3,7 @@ function newFileCache() { const MODULE_NAME = "File Cache"; const INFO_LOG = false; + const ERROR_LOG = true; const logger = newDebugLog(); logger.fileName = MODULE_NAME; @@ -23,74 +24,83 @@ function newFileCache() { function initialize(pDevTeam, pBot, pProduct, pSet, pExchange, pMarket, callBackFunction) { - if (INFO_LOG === true) { logger.write("[INFO] initialize -> Entering function."); } - if (INFO_LOG === true) { logger.write("[INFO] initialize -> key = " + pDevTeam.codeName + "-" + pBot.codeName + "-" + pProduct.codeName); } + try { - let exchange = ecosystem.getExchange(pProduct, pExchange); + if (INFO_LOG === true) { logger.write("[INFO] initialize -> Entering function."); } + if (INFO_LOG === true) { logger.write("[INFO] initialize -> key = " + pDevTeam.codeName + "-" + pBot.codeName + "-" + pProduct.codeName); } - if (exchange === undefined) { + let exchange = ecosystem.getExchange(pProduct, pExchange); - throw "Exchange not supoorted by this pProduct of the ecosystem! - pDevTeam.codeName = " + pDevTeam.codeName + ", pBot.codeName = " + pBot.codeName + ", pProduct.codeName = " + pProduct.codeName + ", pExchange = " + pExchange; + if (exchange === undefined) { - } + throw "Exchange not supoorted by this pProduct of the ecosystem! - pDevTeam.codeName = " + pDevTeam.codeName + ", pBot.codeName = " + pBot.codeName + ", pProduct.codeName = " + pProduct.codeName + ", pExchange = " + pExchange; - fileCloud = newFileCloud(); - fileCloud.initialize(pBot); + } - /* Now we will get the market files */ + fileCloud = newFileCloud(); + fileCloud.initialize(pBot); - for (let i = 0; i < marketFilesPeriods.length; i++) { + /* Now we will get the market files */ - let periodTime = marketFilesPeriods[i][0]; - let periodName = marketFilesPeriods[i][1]; + for (let i = 0; i < marketFilesPeriods.length; i++) { - if (pSet.validPeriods.includes(periodName) === true) { + let periodTime = marketFilesPeriods[i][0]; + let periodName = marketFilesPeriods[i][1]; - fileCloud.getFile(pDevTeam, pBot, pSet, exchange, pMarket, periodName, undefined, undefined, onFileReceived); + if (pSet.validPeriods.includes(periodName) === true) { - function onFileReceived(err, file) { + fileCloud.getFile(pDevTeam, pBot, pSet, exchange, pMarket, periodName, undefined, undefined, onFileReceived); - if (INFO_LOG === true) { logger.write("[INFO] initialize -> onFileReceived -> Entering function."); } + function onFileReceived(err, file) { - switch (err.result) { - case GLOBAL.DEFAULT_OK_RESPONSE.result: { + if (INFO_LOG === true) { logger.write("[INFO] initialize -> onFileReceived -> Entering function."); } - if (INFO_LOG === true) { logger.write("[INFO] initialize -> onFileReceived -> Received OK Response."); } - break; + switch (err.result) { + case GLOBAL.DEFAULT_OK_RESPONSE.result: { + + if (INFO_LOG === true) { logger.write("[INFO] initialize -> onFileReceived -> Received OK Response."); } + break; + } + + case GLOBAL.DEFAULT_FAIL_RESPONSE.result: { + + if (INFO_LOG === true) { logger.write("[INFO] initialize -> onFileReceived -> Received FAIL Response."); } + callBackFunction(GLOBAL.DEFAULT_FAIL_RESPONSE); + return; + } + + case GLOBAL.CUSTOM_FAIL_RESPONSE.result: { + + if (INFO_LOG === true) { logger.write("[INFO] initialize -> onFileReceived -> Received CUSTOM FAIL Response."); } + if (INFO_LOG === true) { logger.write("[INFO] initialize -> onFileReceived -> err.message = " + err.message); } + + callBackFunction(err); + return; + } + + default: { + + if (INFO_LOG === true) { logger.write("[INFO] initialize -> onFileReceived -> Received Unexpected Response."); } + callBackFunction(err); + return; + } } - case GLOBAL.DEFAULT_FAIL_RESPONSE.result: { + files.set(periodTime, file); - if (INFO_LOG === true) { logger.write("[INFO] initialize -> onFileReceived -> Received FAIL Response."); } - callBackFunction(GLOBAL.DEFAULT_FAIL_RESPONSE); - return; - } + filesLoaded++; - case GLOBAL.CUSTOM_FAIL_RESPONSE.result: { + callBackFunction(GLOBAL.DEFAULT_OK_RESPONSE); // Note that the callback is called for every file loaded. - if (INFO_LOG === true) { logger.write("[INFO] initialize -> onFileReceived -> Received CUSTOM FAIL Response."); } - if (INFO_LOG === true) { logger.write("[INFO] initialize -> onFileReceived -> err.message = " + err.message); } - - callBackFunction(err); - return; - } - - default: { - - if (INFO_LOG === true) { logger.write("[INFO] initialize -> onFileReceived -> Received Unexpected Response."); } - callBackFunction(err); - return; - } } - - files.set(periodTime, file); - - filesLoaded++; - - callBackFunction(GLOBAL.DEFAULT_OK_RESPONSE); // Note that the callback is called for every file loaded. - } } + + + } catch (err) { + + if (ERROR_LOG === true) { logger.write("[ERROR] initialize -> err = " + err); } + callBackFunction(GLOBAL.CUSTOM_FAIL_RESPONSE); } }