Fixing more Logging Problems

This commit is contained in:
Luis Fernando Molina committed 2018-06-04 12:45:09 +02:00
1 parent 67d1171511
commit 6b60bd9806
4 files changed
+225 -95

No files matched your search

+71 -31
View File
@@ -9,6 +9,8 @@
let USER_BOT_MODULE;
let COMMONS_MODULE;
const BLOB_STORAGE = require(ROOT_DIR + 'BlobStorage');
const EVENT_HANDLER_MODULE = require(ROOT_DIR + 'EventHandler');
bot.eventHandler = EVENT_HANDLER_MODULE.newEventHandler();
@@ -39,7 +41,6 @@
UI_COMMANDS = pUI_COMMANDS;
processConfig = pProcessConfig;
const BLOB_STORAGE = require(ROOT_DIR + 'BlobStorage');
cloudStorage = BLOB_STORAGE.newBlobStorage(bot);
cloudStorage.initialize("AAPlatform", onInizialized);
@@ -50,8 +51,6 @@
if (err.result === global.DEFAULT_OK_RESPONSE.result) {
/* We needed the cloudStorage initialized for both requesting the bot source code and, later requesting the AACloud config at the ShallWeStop function. */
let filePath;
switch (global.CURRENT_EXECUTION_AT) { // This is what determines if the bot is loaded from the devTeam or an endUser copy.
@@ -64,8 +63,11 @@
break;
}
default: {
console.log(logDisplace + "Root : [ERROR] start -> getBotConfig -> onInizialized -> CURRENT_EXECUTION_AT must be either 'Cloud' or 'Browser' ");
}
logger.write("[ERROR] initialize -> onInizialized -> CURRENT_EXECUTION_AT must be either 'Cloud' or 'Browser'.");
logger.write("[ERROR] initialize -> onInizialized -> global.CURRENT_EXECUTION_AT = " + global.CURRENT_EXECUTION_AT);
callBackFunction(global.DEFAULT_FAIL_RESPONSE);
bot.eventHandler.raiseEvent("Close Log File");
return; }
}
const CLOUD_REQUIRE = require(ROOT_DIR + 'CloudRequire');
@@ -95,7 +97,10 @@
break;
}
default: {
console.log(logDisplace + "Root : [ERROR] start -> getBotConfig -> onInizialized -> CURRENT_EXECUTION_AT must be either 'Cloud' or 'Browser' ");
logger.write("[ERROR] initialize -> onInizialized -> onBotDownloaded -> CURRENT_EXECUTION_AT must be either 'Cloud' or 'Browser'.");
logger.write("[ERROR] initialize -> onInizialized -> onBotDownloaded -> global.CURRENT_EXECUTION_AT = " + global.CURRENT_EXECUTION_AT);
callBackFunction(global.DEFAULT_FAIL_RESPONSE);
return;
}
}
@@ -168,7 +173,6 @@
/* We define here all the modules that the rest of the infraestructure, including the bots themselves can consume. */
const UTILITIES = require(ROOT_DIR + 'CloudUtilities');
const BLOB_STORAGE = require(ROOT_DIR + 'BlobStorage');
const STATUS_REPORT = require(ROOT_DIR + 'StatusReport');
const POLONIEX_CLIENT_MODULE = require(ROOT_DIR + 'PoloniexAPIClient');
const STATUS_DEPENDENCIES = require(ROOT_DIR + 'StatusDependencies');
@@ -507,37 +511,73 @@
try {
if (FULL_LOG === true) { logger.write("[INFO] run -> loopControl -> shallWeStop -> Entering function. "); }
let filePath = "AdvancedAlgos" + "/" + "AACloud";
let fileName = "this.config.json";
cloudStorage = BLOB_STORAGE.newBlobStorage(bot);
cloudStorage.getTextFile(filePath, fileName, onFileReceived);
cloudStorage.initialize("AAPlatform", onInizialized);
function onFileReceived(err, text) {
function onInizialized(err) {
if (err.result !== global.DEFAULT_OK_RESPONSE.result) {
logger.write("[ERROR] run -> loopControl -> shallWeStop -> onFileReceived -> err.message = " + err.message);
bot.eventHandler.raiseEvent("Close Log File");
clearInterval(intervalHandle);
callBackFunction(global.DEFAULT_FAIL_RESPONSE);
return;
}
if (FULL_LOG === true) { logger.write("[INFO] initialize -> onInizialized -> Entering function."); }
try {
if (err.result === global.DEFAULT_OK_RESPONSE.result) {
let configRead = JSON.parse(text);
let filePath;
if (configRead.stopGracefully === false && global.SHALL_BOT_STOP === false) {
continueCallBack();
} else {
stopCallBack();
switch (global.CURRENT_EXECUTION_AT) { // This is what determines if the bot is loaded from the devTeam or an endUser copy.
case "Cloud": {
filePath = global.DEV_TEAM + "/" + "AACloud"; // DevTeams bots only are run at the cloud.
break;
}
case "Browser": {
if (global.SHALL_BOT_STOP === false) {
continueCallBack();
} else {
stopCallBack();
}
break;
}
default: {
logger.write("[ERROR] shallWeStop -> onInizialized -> CURRENT_EXECUTION_AT must be either 'Cloud' or 'Browser'.");
logger.write("[ERROR] shallWeStop -> onInizialized -> global.CURRENT_EXECUTION_AT = " + global.CURRENT_EXECUTION_AT);
bot.eventHandler.raiseEvent("Close Log File");
clearInterval(intervalHandle);
callBackFunction(global.DEFAULT_FAIL_RESPONSE);
return;
}
let fileName = "this.config.json";
cloudStorage.getTextFile(filePath, fileName, onFileReceived);
function onFileReceived(err, text) {
if (err.result !== global.DEFAULT_OK_RESPONSE.result) {
logger.write("[ERROR] run -> loopControl -> shallWeStop -> onFileReceived -> err.message = " + err.message);
bot.eventHandler.raiseEvent("Close Log File");
clearInterval(intervalHandle);
callBackFunction(global.DEFAULT_FAIL_RESPONSE);
return;
}
try {
let configRead = JSON.parse(text);
if (configRead.stopGracefully === false && global.SHALL_BOT_STOP === false) {
continueCallBack();
} else {
stopCallBack();
}
} catch (err) {
logger.write("[ERROR] run -> loopControl -> shallWeStop -> onFileReceived -> err.message = " + err.message);
bot.eventHandler.raiseEvent("Close Log File");
clearInterval(intervalHandle);
callBackFunction(global.DEFAULT_FAIL_RESPONSE);
return;
}
}
}
} catch (err) {
logger.write("[ERROR] run -> loopControl -> shallWeStop -> onFileReceived -> err.message = " + err.message);
bot.eventHandler.raiseEvent("Close Log File");
clearInterval(intervalHandle);
callBackFunction(global.DEFAULT_FAIL_RESPONSE);
return;
}
}
}