From 335ce802e57eb4258b55303222a4a4750c65d3a4 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Fri, 16 Mar 2018 15:43:48 +0100 Subject: [PATCH] Status Report Needs to be LOADED --- .vs/AACloud/v15/.suo | Bin 82944 -> 83968 bytes Context.js | 17 ++++- Status Report.js | 145 +++++++++++++++++-------------------------- 3 files changed, 71 insertions(+), 91 deletions(-) diff --git a/.vs/AACloud/v15/.suo b/.vs/AACloud/v15/.suo index 8a24d68e8dc8d937cf3a8165d6d65eff9d2539b9..7b1ba2e916d9bf90ac04d78b88c7c0622f739ed0 100644 GIT binary patch delta 3040 zcmcImdu&u?7Qg44d#9Z;tyB7bF+-mN*zOcsigjpjDMBO4GFpWg+->C{b_uUe)!?I} z)*$X?!`uUm<+0YgtdZUB+Rojy1{RqTHfuI69grv{pxwkJY=RXPP4O}HoZ;375C0Lr z$uGZi&Ue1^o$q}2o;!i(l)yG+n>S;UBuN%RY=IVs~Ou!&H*k!(nm)aUEe|?^&juebP+1 z*5oO~lI|yD5^RKr@d=v~blhtzvu`53oxtHSYD-soNC^ae zS(;dD>uY@{Uanirav7fs0iCCSTxf6xJQR}oEF8i~avp)JW+iad*eBa$m&p|-dx$5h z_5jHoCx_TgkO^gk`v@}#97mO;&bW|BhE&tY6Fj((%(IDe3DXH&zMBa%3F(AV!bB;j zk<9+dCbP_Aj;V8bZ#Ct)CKvE^u~Ru28VK_Ujf5tuJGvCr##LqqThQmsc#@P=reQVl zS^^bbS(?L1bdt8008~*yU|THMT4q$GoCD0yU8ZHqqS%R>?VBNnpV>R%0(Rte+DB;( zSBFP~K@MITFGV?%3Q;WhGK1d~nHT}LvK(CO)Nj)I{pJVKs?2#uxWng}y)}KTRq{9Dj!R z`JgWk-E-y_{J}Kx#ET@y(=%=H46mKuByu;?ll0q#UMuv)R{aj4-z)UhB7C1qHe4%D zg7PtideOMlSVmX5j;^xqqS8Vp%CGLb{5Dd4w6sNNYpCeoTh^W+!fTp@(e&tR7QIb` zp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za5>BMQg?r8h7)=}9awk*DnY?F2znwhB@!FnmEj+q^;h`Xz?#xxH(@Ctlr01ntI=d?g zR(>wN1=lmh?*by5!ZSBF5kohh4{veBTFF{Osdz7c&L`F(@eeBT--c2@uX z<3*w>txtk-fIG*wkAUTGp1vH&ZL`e;v4kKINcZ+i7G<8&m3-943zj zTH_(6G>OU+qTEIuVd{9wptLjPs2FQEi|9R)hSKAw)%UwfjaYOf9cv$ZR_%*!)uD?y zu%pL<(PO_;zv~wDu~RZc#%_WlOuU$hM;|Ssxfad6Mi-I1P^Omk-uo{;h4RTNsvF|c zfg$_q`oSUFYwLxm>-PD-ow&$EB6FK(*xf>_&>$3H=;SGQ2E8w}p!KCZ)b*|TJ{GA# zecxgb(9^dx<7ZU98-xQwv(P9s2?xmn^~~#s0oV804ZH$V0L4D{fAH>F13uOFY638! zl5sk$L-w*y9tdMN?!&}D0uyIm$>(L9KNx;tx6mT&r}D5jwE@qTHA0#|pFM86XMRQr zm6==V$?ym(1uyC4f=3M{0CZbFGDq_KP!f4H7tEM=%QtJB9ur>3%)$vgbatn`>R|oB zhW&dVko;A*NrC$PdmGUENg>F55bFnvvGHsNo*3MP8^5&T8(+Aw^N-zF_O?QO$MLPv zb=dfBKAyOkgW=EI@^6m8FH;jeqZa%ixdaWLro#;TcyvN=hT%d-){Vz&DLT-+DspH8 z&)F zsn7OwY99Y7NW4tH^YP00I&J4Gnf%$}9P{^tN^(lD|2>KF%#6D~58xxeZ^Khxcay&ZPMBjco`i2t`IT!ZD_t~Kv{lGhCfD;Dla)J(0roc`Pk*F&Eb2oz+?K z(`(@sh}RVZ6Y=a3d%VpDk3g3X_C+q`(qF2YONDO02QI*_nwv3NBh83fog*^ng`CJx zF4RTB;G{>khg~s6p4!>}hu#?`07OK`wq_bf>;0m diff --git a/Context.js b/Context.js index fa1acdcf6..65579ab92 100644 --- a/Context.js +++ b/Context.js @@ -153,15 +153,26 @@ function onInitilized(err) { + if (err.result !== global.DEFAULT_OK_RESPONSE.result) { + logger.write("[ERROR] initialize -> getStatusReport -> onInitilized -> err = " + err.message); + callBackFunction(err); + return; + } + + statusReportModule.load(onLoad); + } + + function onLoad(err) { + switch (err.result) { case global.DEFAULT_OK_RESPONSE.result: { - logger.write("[INFO] initialize -> getStatusReport -> Execution finished well. :-)"); + logger.write("[INFO] initialize -> getStatusReport -> onLoad -> Execution finished well. :-)"); thisObject.statusReport = statusReportModule.file; getExecutionHistory(callBack); return; } case global.CUSTOM_OK_RESPONSE.result: { // We need to see if we can handle this. - logger.write("[ERROR] initialize -> getStatusReport -> err.message = " + err.message); + logger.write("[ERROR] initialize -> getStatusReport -> onLoad -> err.message = " + err.message); if (err.message === "Status Report was never created.") { createConext(callBack); @@ -172,7 +183,7 @@ } default: { - logger.write("[ERROR] initialize -> getStatusReport -> Operation Failed."); + logger.write("[ERROR] initialize -> getStatusReport -> onLoad -> Operation Failed."); callBackFunction(err); return; } diff --git a/Status Report.js b/Status Report.js index 0bd747308..a813d2dc1 100644 --- a/Status Report.js +++ b/Status Report.js @@ -16,6 +16,7 @@ let thisObject = { file: undefined, // Here we have the JSON object representing the file content. initialize: initialize, + load: load, save: save }; @@ -69,7 +70,8 @@ if (err.result === global.DEFAULT_OK_RESPONSE.result) { - getFile(onDone); + if (FULL_LOG === true) { logger.write("[INFO] initialize -> initializeStorage -> onInizialized -> Entering function."); } + callBackFunction(global.DEFAULT_OK_RESPONSE); } else { logger.write("[ERROR] initialize -> initializeStorage -> onInizialized -> err = " + err.message); @@ -77,107 +79,74 @@ } } } + } catch (err) { + logger.write("[ERROR] initialize -> err = " + err.message); + callBackFunction(global.DEFAULT_FAIL_RESPONSE); + } + } - function onDone(err) { - try { + function load(callBackFunction) { - switch (err.result) { - case global.DEFAULT_OK_RESPONSE.result: { - logger.write("[INFO] initialize -> onDone -> Execution finished well. :-)"); - callBackFunction(global.DEFAULT_OK_RESPONSE); - 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] initialize -> onDone -> Retry Later. Requesting Execution Retry."); - callBackFunction(err); - return; - } - case global.DEFAULT_FAIL_RESPONSE.result: { // This is an unexpected exception that we do not know how to handle. - logger.write("[ERROR] initialize -> onDone -> Operation Failed. Aborting the process."); - callBackFunction(err); - return; - } - case global.CUSTOM_OK_RESPONSE.result: { - logger.write("[INFO] initialize -> onDone -> Execution finished with some expected issue."); - callBackFunction(err); - return; - } + try { + + if (FULL_LOG === true) { logger.write("[INFO] initialize -> load -> Entering function."); } + + let fileName = "Status.Report.json" + let filePath = global.FILE_PATH_ROOT + "/Reports/" + bot.process; + + if (FULL_LOG === true) { logger.write("[INFO] initialize -> load -> fileName = " + fileName); } + if (FULL_LOG === true) { logger.write("[INFO] initialize -> load -> filePath = " + filePath); } + + cloudStorage.getTextFile(filePath, fileName, onFileReceived); + + function onFileReceived(err, text) { + + if (err.result === global.CUSTOM_FAIL_RESPONSE.result && err.message === 'Folder does not exist.') { + logger.write("[INFO] initialize -> load -> onFileReceived -> err = " + err.message); + + /* In this case we can assume that this is the first execution ever of this bot.*/ + + thisObject.file = JSON.parse('{}'); + + let customOK = { + result: global.CUSTOM_OK_RESPONSE.result, + message: "Status Report was never created." } - - } catch (err) { - logger.write("[ERROR] initialize -> onDone -> err = " + err.message); - callBackFunction(global.DEFAULT_FAIL_RESPONSE); + logger.write("[WARN] initialize -> load -> onFileReceived -> customOK = " + err.message); + callBackFunction(customOK); + return; } - } - function getFile(callBack) { + if (err.result !== global.DEFAULT_OK_RESPONSE.result) { + logger.write("[ERROR] initialize -> load -> onFileReceived -> err = " + err.message); + callBackFunction(err); + return; + } + + if (FULL_LOG === true) { + logger.write("[INFO] initialize -> load -> onFileReceived -> Content received = " + text); + } try { - if (FULL_LOG === true) { logger.write("[INFO] initialize -> getFile -> Entering function."); } - - let fileName = "Status.Report.json" - 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); } - - cloudStorage.getTextFile(filePath, fileName, onFileReceived); - - function onFileReceived(err, text) { - - if (err.result === global.CUSTOM_FAIL_RESPONSE.result && err.message === 'Folder does not exist.') { - logger.write("[INFO] initialize -> getFile -> onFileReceived -> err = " + err.message); - - /* In this case we can assume that this is the first execution ever of this bot.*/ - - thisObject.file = JSON.parse('{}'); - - let customOK = { - result: global.CUSTOM_OK_RESPONSE.result, - message: "Status Report was never created." - } - logger.write("[WARN] initialize -> getFile -> onFileReceived -> customOK = " + err.message); - callBack(customOK); - return; - } - - if (err.result !== global.DEFAULT_OK_RESPONSE.result) { - logger.write("[ERROR] initialize -> getFile -> onFileReceived -> err = " + err.message); - callBack(err); - return; - } - - if (FULL_LOG === true) { - logger.write("[INFO] initialize -> getFile -> onFileReceived -> Content received = " + text); - } - - try { - - thisObject.file = JSON.parse(text); - callBack(global.DEFAULT_OK_RESPONSE); - - } catch (err) { - - /* - It might happen that the file content is corrupt. We will consider this as a temporary situation, since sometimes the file - is being updated at the moment of the read. The bot can not run without a valid Status Report but we can request the platform to retry later. - */ - - logger.write("[ERROR] initialize -> getFile -> onFileReceived -> Bot cannot execute without a valid Status report. -> Err = " + err.message); - callBack(global.DEFAULT_RETRY_RESPONSE); - } - } + thisObject.file = JSON.parse(text); + callBackFunction(global.DEFAULT_OK_RESPONSE); } catch (err) { - logger.write("[ERROR] initialize -> getFile -> err = " + err.message); - callBack(global.DEFAULT_FAIL_RESPONSE); + + /* + It might happen that the file content is corrupt. We will consider this as a temporary situation, since sometimes the file + is being updated at the moment of the read. The bot can not run without a valid Status Report but we can request the platform to retry later. + */ + + logger.write("[ERROR] initialize -> load -> onFileReceived -> Bot cannot execute without a valid Status report. -> Err = " + err.message); + callBackFunction(global.DEFAULT_RETRY_RESPONSE); } } } catch (err) { - logger.write("[ERROR] initialize -> err = " + err.message); - callBack(global.DEFAULT_FAIL_RESPONSE); + logger.write("[ERROR] initialize -> load -> err = " + err.message); + callBackFunction(global.DEFAULT_FAIL_RESPONSE); } }