From 0e110abee4ca98ab783b70fd8f97672bfc2fb8db Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Wed, 7 Mar 2018 19:29:44 +0100 Subject: [PATCH] .getTextFile dependencies fixed --- .vs/AACloudPlatform/v15/.suo | Bin 73728 -> 74240 bytes Context.js | 64 +++++++++++++++++++++++++++-------- Datasource.js | 22 ++++++------ 3 files changed, 61 insertions(+), 25 deletions(-) diff --git a/.vs/AACloudPlatform/v15/.suo b/.vs/AACloudPlatform/v15/.suo index 9cf92d21d4ad428d47c2ce1971177ac0e57d170d..546a023974a7cd1e2a70ccf72c6c401dafadd7f3 100644 GIT binary patch delta 632 zcmZoTz|wGpWrD$EgFH?N0R{$s1_lOZApZCN|9>FGzzD>08v}ncGO|xrWRhnsD1WWw zG`W!JG6zt>e?6e=REiNy9c(@ylIY|T8UM-7^0AW@2G$semU$QxL>UtJNu=r$! zsiu?d=N3)oU(7SPY>~$1RkQpUH_xB5i3uVP*T=!l;If3##mZn&6Vqh=DY+mGo68op zGfob?6F7O_5}wVmOP+J0yJX#Z&dC$@h;0_$@rrfRzI6hVL#M8ueBlnuDph$$&MSdz&33zpVP@Wx$e67WQ8>flMgIaoE&<~SxgA%4;WB~GF+B{yft~k zZNAOAw-cEJU%(VFs2}(PVo#obH*WIB9pRJTuN9nJy+?cVFHla=0x!@V@w>%n2c zxuDpEf~`QdqZx3aknTRJ83U7cyPu z-~)>50rBJoCln?dF!5}zVE)3yy1}W&#C~%j+a>PF&H{#;ON9IxIT?T^{pUp}<(T|M z_{!!JQdW$cnZ%sfI0S)GAQwPQ;+R|_cb=0Gq=_9#baRPp3peA6%|A7~<9U055+Xnh zqQf=^cC6=~bZ*_`*z=30UtnWonY`}Y>P^#FST?g<`NKGwXI9qa0}ps7Uzo44dH$SD zOp^oeuV2)}G?{Tu)@1(2Jew;QwKFoCnYc{8cq?%7z9l@HW0ySVM7Lqxdd}$w*%*a4 zi|u&D%AAu}vT5Hs0Tc@tU0_?r#0W7KVO=8QWX1C$lNHt|Og^wwadN~hXHjXOn;}5` zKpBu>48$&z181+;9C6!{NidKRD$AgLAO*-apFW?RF>&(5#o?3RuN9nJw?}*PFH zlOHV+oqm9ekq6|j$-WN`Pv_@m{K!<4i{h`%e;+e*Oygo)G5O&VvF$+R4vd@sy`3dS LvLm*G93cS!DTln# diff --git a/Context.js b/Context.js index 30e64cadd..057f67117 100644 --- a/Context.js +++ b/Context.js @@ -134,27 +134,36 @@ function getStatusReport(callBack) { try { + + if (LOG_INFO === true) { logger.write("[INFO] initialize -> getStatusReport -> Entering function."); } + /* If the process run and was interrupted, there should be a status report that allows us to resume execution. */ let fileName = "Status.Report.json" let filePath = EXCHANGE_NAME + "/" + bot.codeName + "/" + bot.dataSetVersion + "/Processes/" + bot.process; - cloudStorage.getTextFile(filePath, fileName, onFileReceived, true); + cloudStorage.getTextFile(filePath, fileName, onFileReceived); - function onFileReceived(text) { + function onFileReceived(err, text) { + + if (err.result !== global.DEFAULT_OK_RESPONSE.result) { + logger.write("[ERROR] initialize -> getStatusReport -> onFileReceived -> err = " + err.message); + callBack(err); + return; + } + + if (LOG_INFO === true) { + logger.write("[INFO] initialize -> getStatusReport -> onFileReceived -> Content received = " + text); + } try { thisObject.statusReport = JSON.parse(text); if (thisObject.statusReport.lastExecution === undefined) { - createConext(callBack); - } else { - getExecutionHistory(callBack); - } } catch (err) { @@ -167,10 +176,11 @@ */ - logger.write("[ERROR] initialize -> getStatusReport -> Bot cannot execute without the Status report. -> Err = " + err.message); + logger.write("[ERROR] initialize -> getStatusReport -> onFileReceived -> Bot cannot execute without the Status report. -> Err = " + err.message); callBack(global.DEFAULT_FAIL_RESPONSE); } } + } catch (err) { logger.write("[ERROR] initialize -> getExecutionHistory -> err = " + err.message); callBack(global.DEFAULT_FAIL_RESPONSE); @@ -180,12 +190,24 @@ function getExecutionHistory(callBack) { try { + if (LOG_INFO === true) { logger.write("[INFO] initialize -> getExecutionHistory -> Entering function."); } + let fileName = "Execution.History.json" let filePath = EXCHANGE_NAME + "/" + bot.codeName + "/" + bot.dataSetVersion + "/Output/" + bot.process; - cloudStorage.getTextFile(filePath, fileName, onFileReceived, true); + cloudStorage.getTextFile(filePath, fileName, onFileReceived); - function onFileReceived(text) { + function onFileReceived(err, text) { + + if (err.result !== global.DEFAULT_OK_RESPONSE.result) { + logger.write("[ERROR] initialize -> getExecutionHistory -> onFileReceived -> err = " + err.message); + callBack(err); + return; + } + + if (LOG_INFO === true) { + logger.write("[INFO] initialize -> getExecutionHistory -> onFileReceived -> Content received = " + text); + } try { @@ -202,10 +224,11 @@ */ - logger.write("[ERROR] initialize -> getExecutionHistory -> Bot cannot execute without the Execution History. -> Err = " + err.message); + logger.write("[ERROR] initialize -> getExecutionHistory -> onFileReceived -> Bot cannot execute without the Execution History. -> Err = " + err.message); callBack(global.DEFAULT_FAIL_RESPONSE); } } + } catch (err) { logger.write("[ERROR] initialize -> getExecutionHistory -> err = " + err.message); callBack(global.DEFAULT_FAIL_RESPONSE); @@ -215,22 +238,32 @@ function getExecutionContext(callBack) { try { + if (LOG_INFO === true) { logger.write("[INFO] initialize -> getExecutionContext -> Entering function."); } + let date = new Date(thisObject.statusReport.lastExecution); let fileName = "Execution.Context.json" let dateForPath = date.getUTCFullYear() + '/' + utilities.pad(date.getUTCMonth() + 1, 2) + '/' + utilities.pad(date.getUTCDate(), 2) + '/' + utilities.pad(date.getUTCHours(), 2) + '/' + utilities.pad(date.getUTCMinutes(), 2); let filePath = EXCHANGE_NAME + "/" + bot.codeName + "/" + bot.dataSetVersion + "/Output/" + bot.process + "/" + dateForPath; - cloudStorage.getTextFile(filePath, fileName, onFileReceived, true); + cloudStorage.getTextFile(filePath, fileName, onFileReceived); - function onFileReceived(text) { + function onFileReceived(err, text) { + + if (err.result !== global.DEFAULT_OK_RESPONSE.result) { + logger.write("[ERROR] initialize -> getExecutionContext -> onFileReceived -> err = " + err.message); + callBack(err); + return; + } + + if (LOG_INFO === true) { + logger.write("[INFO] initialize -> getExecutionContext -> onFileReceived -> Content received = " + text); + } try { thisObject.executionContext = JSON.parse(text); - thisObject.executionContext.transactions = []; // We record here the transactions that happened duting this execution. - callBack(global.DEFAULT_OK_RESPONSE); } catch (err) { @@ -243,7 +276,7 @@ */ - logger.write("[ERROR] initialize -> getExecutionContext -> Bot cannot execute without the Execution Context. -> Err = " + err.message); + logger.write("[ERROR] initialize -> getExecutionContext -> onFileReceived -> Bot cannot execute without the Execution Context. -> Err = " + err.message); callBack(global.DEFAULT_FAIL_RESPONSE); } } @@ -257,6 +290,7 @@ function createConext(callBack) { try { + if (LOG_INFO === true) { logger.write("[INFO] initialize -> createConext -> Entering function."); } /* When the bot is executed for the very first time, there are a few files that do not exist and need to be created, and that diff --git a/Datasource.js b/Datasource.js index b9de70be1..ad07b8d8b 100644 --- a/Datasource.js +++ b/Datasource.js @@ -418,26 +418,28 @@ pFileService.getTextFile(pFilePath, pFileName, onFileReceived); - function onFileReceived(text) { + function onFileReceived(err, text) { - let data; + if (err.result !== global.DEFAULT_OK_RESPONSE.result) { + logger.write("[ERROR] initialize -> getFile -> onFileReceived -> err = " + err.message); + outerCallBack(err); + return; + } try { - data = JSON.parse(text); + let data = JSON.parse(text); + innerCallBack(data); } catch (err) { - - data = JSON.parse("[]"); - + logger.write("[ERROR] initialize -> getFile -> onFileReceived -> Parsing JSON -> err = " + err.message); + outerCallBack(err); + return; } - - innerCallBack(data); - } } catch (err) { - logger.write("[ERROR] getPatterns -> err = " + err.message); + logger.write("[ERROR] initialize -> getFile -> err = " + err.message); outerCallBack("Operation Failed"); } }