From c04365ea6aae2671518afec741b0dfebe2bb426e Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Thu, 24 May 2018 15:38:04 +0200 Subject: [PATCH] Indicator and Extractors types are now up to date --- ExtractionBotProcessMainLoop.js | 62 +++++++++++---------------------- IndicatorBotProcessMainLoop.js | 62 +++++++++++---------------------- 2 files changed, 40 insertions(+), 84 deletions(-) diff --git a/ExtractionBotProcessMainLoop.js b/ExtractionBotProcessMainLoop.js index 9d0b13e6b..e2780116a 100644 --- a/ExtractionBotProcessMainLoop.js +++ b/ExtractionBotProcessMainLoop.js @@ -46,62 +46,40 @@ if (err.result === global.DEFAULT_OK_RESPONSE.result) { - let filePath = bot.devTeam + "/" + bot.repo + "/" + pProcessConfig.name; - let fileName = "User.Bot.js"; + /* We needed the cloudStorage initialized for both requesting the bot source code and, later requesting the AACloud condig at ShallWeStop function. */ - cloudStorage.getTextFile(filePath, fileName, onFileReceived); + const CLOUD_REQUIRE = require(ROOT_DIR + 'CloudRequire'); + let cloudRequire = CLOUD_REQUIRE.newCloudRequire(bot, DEBUG_MODULE); - function onFileReceived(err, text) { + cloudRequire.downloadBot(cloudStorage, pProcessConfig, onBotDownloaded); + + function onBotDownloaded(err, pMODULE) { if (err.result !== global.DEFAULT_OK_RESPONSE.result) { - logger.write("[ERROR] initialize -> onInizialized -> onFileReceived -> err.message = " + err.message); + logger.write("[ERROR] initialize -> onInizialized -> onBotDownloaded -> err.message = " + err.message); callBackFunction(global.DEFAULT_FAIL_RESPONSE); bot.eventHandler.raiseEvent("Loop Finished"); return; } - try { + USER_BOT_MODULE = pMODULE; - USER_BOT_MODULE = {}; - USER_BOT_MODULE.newUserBot = eval(text); + cloudRequire.downloadCommons(cloudStorage, onCommonsDownloaded); - filePath = bot.devTeam + "/" + bot.repo; - fileName = "Commons.js"; + function onCommonsDownloaded(err, pMODULE) { - cloudStorage.getTextFile(filePath, fileName, onFileReceived); + if (err.result !== global.DEFAULT_OK_RESPONSE.result) { - function onFileReceived(err, text) { - - if (err.result !== global.DEFAULT_OK_RESPONSE.result) { - - // Nothing happens since COMMONS modules are optional. - callBackFunction(global.DEFAULT_OK_RESPONSE); - return; - } - - try { - - COMMONS_MODULE = {}; - COMMONS_MODULE.newCommons = eval(text); - - filePath = bot.devTeam + "/" + bot.repo; - fileName = "Commons.js"; - - callBackFunction(global.DEFAULT_OK_RESPONSE); - - } catch (err) { - logger.write("[ERROR] initialize -> onInizialized -> onFileReceived -> onFileReceived -> err.message = " + err.message); - callBackFunction(global.DEFAULT_FAIL_RESPONSE); - bot.eventHandler.raiseEvent("Loop Finished"); - return; - } + logger.write("[ERROR] initialize -> onInizialized -> onBotDownloaded -> onCommonsDownloaded -> err.message = " + err.message); + callBackFunction(global.DEFAULT_FAIL_RESPONSE); + bot.eventHandler.raiseEvent("Loop Finished"); + return; } - } catch (err) { - logger.write("[ERROR] initialize -> onInizialized -> onFileReceived -> err.message = " + err.message); - callBackFunction(global.DEFAULT_FAIL_RESPONSE); - bot.eventHandler.raiseEvent("Loop Finished"); - return; + + COMMONS_MODULE = pMODULE; + + callBackFunction(global.DEFAULT_OK_RESPONSE); } } @@ -484,7 +462,7 @@ let configRead = JSON.parse(text); - if (configRead.stopGracefully === false) { + if (configRead.stopGracefully === false && global.SHALL_BOT_STOP === false) { continueCallBack(); } else { stopCallBack(); diff --git a/IndicatorBotProcessMainLoop.js b/IndicatorBotProcessMainLoop.js index c19d44dd3..41f3c5ead 100644 --- a/IndicatorBotProcessMainLoop.js +++ b/IndicatorBotProcessMainLoop.js @@ -46,62 +46,40 @@ if (err.result === global.DEFAULT_OK_RESPONSE.result) { - let filePath = bot.devTeam + "/" + bot.repo + "/" + pProcessConfig.name; - let fileName = "User.Bot.js"; + /* We needed the cloudStorage initialized for both requesting the bot source code and, later requesting the AACloud condig at ShallWeStop function. */ - cloudStorage.getTextFile(filePath, fileName, onFileReceived); + const CLOUD_REQUIRE = require(ROOT_DIR + 'CloudRequire'); + let cloudRequire = CLOUD_REQUIRE.newCloudRequire(bot, DEBUG_MODULE); - function onFileReceived(err, text) { + cloudRequire.downloadBot(cloudStorage, pProcessConfig, onBotDownloaded); + + function onBotDownloaded(err, pMODULE) { if (err.result !== global.DEFAULT_OK_RESPONSE.result) { - logger.write("[ERROR] initialize -> onInizialized -> onFileReceived -> err.message = " + err.message); + logger.write("[ERROR] initialize -> onInizialized -> onBotDownloaded -> err.message = " + err.message); callBackFunction(global.DEFAULT_FAIL_RESPONSE); bot.eventHandler.raiseEvent("Loop Finished"); return; } - try { + USER_BOT_MODULE = pMODULE; - USER_BOT_MODULE = {}; - USER_BOT_MODULE.newUserBot = eval(text); + cloudRequire.downloadCommons(cloudStorage, onCommonsDownloaded); - filePath = bot.devTeam + "/" + bot.repo; - fileName = "Commons.js"; + function onCommonsDownloaded(err, pMODULE) { - cloudStorage.getTextFile(filePath, fileName, onFileReceived); + if (err.result !== global.DEFAULT_OK_RESPONSE.result) { - function onFileReceived(err, text) { - - if (err.result !== global.DEFAULT_OK_RESPONSE.result) { - - // Nothing happens since COMMONS modules are optional. - callBackFunction(global.DEFAULT_OK_RESPONSE); - return; - } - - try { - - COMMONS_MODULE = {}; - COMMONS_MODULE.newCommons = eval(text); - - filePath = bot.devTeam + "/" + bot.repo; - fileName = "Commons.js"; - - callBackFunction(global.DEFAULT_OK_RESPONSE); - - } catch (err) { - logger.write("[ERROR] initialize -> onInizialized -> onFileReceived -> onFileReceived -> err.message = " + err.message); - callBackFunction(global.DEFAULT_FAIL_RESPONSE); - bot.eventHandler.raiseEvent("Loop Finished"); - return; - } + logger.write("[ERROR] initialize -> onInizialized -> onBotDownloaded -> onCommonsDownloaded -> err.message = " + err.message); + callBackFunction(global.DEFAULT_FAIL_RESPONSE); + bot.eventHandler.raiseEvent("Loop Finished"); + return; } - } catch (err) { - logger.write("[ERROR] initialize -> onInizialized -> onFileReceived -> err.message = " + err.message); - callBackFunction(global.DEFAULT_FAIL_RESPONSE); - bot.eventHandler.raiseEvent("Loop Finished"); - return; + + COMMONS_MODULE = pMODULE; + + callBackFunction(global.DEFAULT_OK_RESPONSE); } } @@ -456,7 +434,7 @@ let configRead = JSON.parse(text); - if (configRead.stopGracefully === false) { + if (configRead.stopGracefully === false && global.SHALL_BOT_STOP === false) { continueCallBack(); } else { stopCallBack();