Loging at the devTeam Storage

This commit is contained in:
Luis Fernando Molina committed 2018-05-20 12:02:29 +02:00
1 parent 991ed20a24
commit 9aab0514aa
17 files changed
+313 -59

No files matched your search

+7 -6
View File
@@ -11,6 +11,13 @@
const MODULE_NAME = "Assistant";
let bot = BOT;
const logger = DEBUG_MODULE.newDebugLog();
logger.fileName = MODULE_NAME;
logger.bot = bot;
logger.initialize();
let thisObject = {
dataDependencies: undefined,
initialize: initialize,
@@ -26,12 +33,6 @@
sendMessage: sendMessage
};
let bot = BOT;
const logger = DEBUG_MODULE.newDebugLog();
logger.fileName = MODULE_NAME;
logger.bot = bot;
let utilities = UTILITIES.newUtilities(bot);
let exchangePositions = []; // These are the open positions at the exchange at the account the bot is authorized to use.
+14 -7
View File
@@ -1,24 +1,22 @@
exports.newBlobStorage = function newBlobStorage(BOT) {
const FULL_LOG = true;
const LOG_FILE_CONTENT = false;
let FULL_LOG = true;
let LOG_FILE_CONTENT = false;
let bot = BOT;
const ROOT_DIR = './';
const MODULE_NAME = "Blob Storage";
var util = require('util');
var guid = require('node-uuid');
var crypto = require('crypto');
var storage = require('azure-storage');
let storage = require('azure-storage');
const DEBUG_MODULE = require('./Debug Log');
const logger = DEBUG_MODULE.newDebugLog();
logger.fileName = MODULE_NAME;
logger.bot = bot;
let thisObject = {
initialize: initialize,
createFolder: createFolder,
@@ -34,10 +32,19 @@ exports.newBlobStorage = function newBlobStorage(BOT) {
return thisObject;
function initialize(pBotDataOwner, callBackFunction) {
function initialize(pBotDataOwner, callBackFunction, disableLogging) {
try {
if (disableLogging === true) {
FULL_LOG = false;
LOG_FILE_CONTENT = false;
} else {
logger.initialize();
}
if (pBotDataOwner === undefined) {
devTeamDataOwner = bot.devTeam;
+10 -6
View File
@@ -3,6 +3,15 @@
const FULL_LOG = true;
const LOG_FILE_CONTENT = false;
let bot = BOT;
const MODULE_NAME = "Context";
const logger = DEBUG_MODULE.newDebugLog();
logger.fileName = MODULE_NAME;
logger.bot = bot;
logger.initialize();
/*
This module allows deals with keeping the context between different executions of the bot.
@@ -14,7 +23,7 @@
*/
const MODULE_NAME = "Context";
/*
@@ -68,13 +77,8 @@
*/
let bot = BOT;
let statusReportModule;
const logger = DEBUG_MODULE.newDebugLog();
logger.fileName = MODULE_NAME;
logger.bot = bot;
/* Utilities needed. */
let utilities = UTILITIES.newUtilities(bot);
+8 -6
View File
@@ -5,18 +5,20 @@
const MODULE_NAME = "Data Dependencies";
let thisObject = {
dataSets: new Map(),
initialize: initialize,
keys: []
};
let bot = BOT;
let ownerBot; // This is the bot owner of the Data Set.
const logger = DEBUG_MODULE.newDebugLog();
logger.fileName = MODULE_NAME;
logger.bot = bot;
logger.initialize();
let thisObject = {
dataSets: new Map(),
initialize: initialize,
keys: []
};
return thisObject;
+8 -5
View File
@@ -5,6 +5,13 @@
const MODULE_NAME = "Data Set";
let bot = BOT;
const logger = DEBUG_MODULE.newDebugLog();
logger.bot = bot;
logger.fileName = MODULE_NAME;
logger.initialize();
let thisObject = {
file: undefined, // Here we have the JSON object representing the file content.
initialize: initialize,
@@ -12,11 +19,7 @@
createTextFile: createTextFile
};
let bot = BOT;
let dependencyConfig;
const logger = DEBUG_MODULE.newDebugLog();
logger.bot = bot;
let dependencyConfig;
/* Utilities needed. */
+65 -4
View File
@@ -1,5 +1,6 @@
exports.newDebugLog = function newDebugLog() {
const ROOT_DIR = './';
const MODULE_NAME = "Debug Log";
const fileSystem = require('fs');
@@ -7,7 +8,9 @@
const dateString = currentDate.getUTCFullYear() + '-' + pad(currentDate.getUTCMonth() + 1, 2) + '-' + pad(currentDate.getUTCDate(), 2) + '-' + pad(currentDate.getUTCHours(), 2) + '-' + pad(currentDate.getUTCMinutes(), 2);
const randomId = parseInt(Math.random() * 1000000);
let executionPath = global.EXECUTION_DATETIME.getUTCFullYear() + '-' + pad(global.EXECUTION_DATETIME.getUTCMonth() + 1, 2) + '-' + pad(global.EXECUTION_DATETIME.getUTCDate(), 2) + '.' + pad(global.EXECUTION_DATETIME.getUTCHours(), 2) + '-' + pad(global.EXECUTION_DATETIME.getUTCMinutes(), 2);
let executionDatetime = global.EXECUTION_DATETIME.toISOString();
let executionPath = global.EXECUTION_DATETIME.getUTCFullYear() + '-' + pad(global.EXECUTION_DATETIME.getUTCMonth() + 1, 2) + '-' + pad(global.EXECUTION_DATETIME.getUTCDate(), 2) + 'T' + pad(global.EXECUTION_DATETIME.getUTCHours(), 2) + '-' + pad(global.EXECUTION_DATETIME.getUTCMinutes(), 2) + '-' + pad(global.EXECUTION_DATETIME.getUTCSeconds(), 2);
let fileNumber = 1;
let messageId = 0;
let firstCall = true;
@@ -19,11 +22,64 @@
bot: undefined,
fileName: undefined,
forceLoopSplit: false, // When set to 'true' this will force that the logs of the current module are split in many different Loop folders.
write: write
write: write,
initialize: initialize
};
let blobContent = "";
return thisObject;
function initialize() {
thisObject.bot.eventHandler.listenToEvent("Loop Finished", onLoopFinished);
}
function onLoopFinished(event) {
try {
const BLOB_STORAGE = require(ROOT_DIR + 'Blob Storage');
let cloudStorage = BLOB_STORAGE.newBlobStorage(thisObject.bot);
cloudStorage.initialize(thisObject.bot, onInizialized, true);
function onInizialized(err) {
if (err.result === global.DEFAULT_OK_RESPONSE.result) {
let filePath = thisObject.bot.filePathRoot + "/Logs/" + thisObject.bot.process + "/" + executionDatetime;
if (thisObject.bot.debug.year !== undefined) {
filePath = filePath + "/" + thisObject.bot.debug.year + "/" + thisObject.bot.debug.month;
}
if (loopCounter === undefined) { loopCounter = 0 };
filePath = filePath + "/Loop." + loopCounter;
cloudStorage.createTextFile(filePath, thisObject.fileName + ".txt", blobContent + '\n', onFileCreated);
function onFileCreated(err) {
if (err.result !== global.DEFAULT_OK_RESPONSE.result) {
console.log("[ERROR] onLoopFinished -> onInizialized -> onFileCreated -> err = " + err.message);
return;
}
}
} else {
console.log("[ERROR] onLoopFinished -> onInizialized -> err = " + err.message);
}
}
} catch (err) {
console.log("[ERROR] onLoopFinished -> err = " + err.message);
}
}
function createFolders() {
try {
@@ -127,6 +183,7 @@
loopCounter = thisObject.bot.loopCounter;
createLoopFolder();
blobContent = "";
}
} else {
@@ -138,7 +195,7 @@
}
}
let filePath = getCurrentLogFile(folderPath + "/" + dateString + "---" + randomId + "---", this.fileName);
let filePath = getCurrentLogFile(folderPath + "/" + dateString + "---" + randomId + "---", thisObject.fileName);
let newDate = new Date();
newDate = newDate.toISOString();
@@ -147,7 +204,11 @@
try {
fileSystem.appendFileSync(filePath, '\r\n' + newDate + " " + messageId + " " + Message);
let fileLine = '\r\n' + newDate + " " + messageId + " " + Message;
fileSystem.appendFileSync(filePath, fileLine);
blobContent = blobContent + fileLine;
}
catch (err) {
+63
View File
@@ -0,0 +1,63 @@
exports.newEventHandler = function newEventHandler() {
const CONSOLE_LOG = false;
let thisObject = {
name: undefined, // This is for debugging purposes only.
parentEventHandler: undefined, // Here we store the parent cointainer zoom object.
listenToEvent: listenToEvent,
raiseEvent: raiseEvent,
initialize: initialize
};
var eventHandlers = []; // Here we store all the functions we will call when an event is comming.
return thisObject;
function initialize() {
}
function listenToEvent(eventType, handler, extraData) {
eventHandlers.push([eventType, handler, extraData]);
if (thisObject.name !== undefined && CONSOLE_LOG === true) {
console.log("Event Handler named " + thisObject.name + " received a request to listenToEvent " + eventType + " and call " + (handler.toString()).substring(0, 50));
}
}
function raiseEvent(eventType, event) {
if (thisObject.name !== undefined && CONSOLE_LOG === true) {
console.log("Event Handler named " + thisObject.name + " received a request to raiseEvent " + eventType + " with this data " + (event.toString()).substring(0, 50));
}
for (var i = 0; i < eventHandlers.length; i++) {
/* We will execute all the functions listening to this event type. */
if (eventHandlers[i][0] === eventType) {
var handler = eventHandlers[i][1];
var extraData = eventHandlers[i][2];
if (thisObject.name !== undefined && CONSOLE_LOG === true) {
console.log("Event Handler named " + thisObject.name + " received a request to raiseEvent " + eventType + " and will call this handler: " + (handler.toString()).substring(0,50));
}
handler(event, extraData);
}
}
}
}
+7 -6
View File
@@ -10,6 +10,13 @@
const MODULE_NAME = "Exchange API";
let bot = BOT;
const logger = DEBUG_MODULE.newDebugLog();
logger.fileName = MODULE_NAME;
logger.bot = bot;
logger.initialize();
let thisObject = {
initialize: initialize,
getOpenPositions: getOpenPositions,
@@ -19,12 +26,6 @@
getTicker: getTicker
};
let bot = BOT;
const logger = DEBUG_MODULE.newDebugLog();
logger.fileName = MODULE_NAME;
logger.bot = bot;
let poloniexApiClient;
return thisObject;
+35 -4
View File
@@ -9,11 +9,15 @@
let USER_BOT_MODULE;
let COMMONS_MODULE;
const EVENT_HANDLER_MODULE = require(ROOT_DIR + 'EventHandler');
bot.eventHandler = EVENT_HANDLER_MODULE.newEventHandler();
const DEBUG_MODULE = require(ROOT_DIR + 'Debug Log');
const logger = DEBUG_MODULE.newDebugLog();
logger.fileName = MODULE_NAME;
logger.bot = bot;
logger.forceLoopSplit = true;
logger.initialize();
let thisObject = {
initialize: initialize,
@@ -42,6 +46,7 @@
} catch (err) {
logger.write("[ERROR] initialize -> err = " + err.message);
bot.eventHandler.raiseEvent("Loop Finished");
callBackFunction(global.DEFAULT_FAIL_RESPONSE);
}
}
@@ -122,6 +127,7 @@
}
case global.DEFAULT_FAIL_RESPONSE.result: { // This is an unexpected exception that we do not know how to handle.
logger.write("[ERROR] run -> loop -> initializeStatusDependencies -> onInizialized -> Operation Failed. Aborting the process.");
bot.eventHandler.raiseEvent("Loop Finished");
callBackFunction(err);
return;
}
@@ -129,6 +135,7 @@
logger.write("[ERROR] run -> loop -> initializeStatusDependencies -> onInizialized -> Unhandled err.result received. -> err.result = " + err.result);
logger.write("[ERROR] run -> loop -> initializeStatusDependencies -> onInizialized -> Unhandled err.result received. -> err.message = " + err.message);
bot.eventHandler.raiseEvent("Loop Finished");
callBackFunction(global.DEFAULT_FAIL_RESPONSE);
return;
}
@@ -136,12 +143,14 @@
} catch (err) {
logger.write("[ERROR] run -> loop -> initializeStatusDependencies -> onInizialized -> err = " + err.message);
bot.eventHandler.raiseEvent("Loop Finished");
callBackFunction(err);
}
}
} catch (err) {
logger.write("[ERROR] run -> loop -> initializeStatusDependencies -> err = " + err.message);
bot.eventHandler.raiseEvent("Loop Finished");
callBackFunction(err);
}
}
@@ -176,6 +185,7 @@
}
case global.DEFAULT_FAIL_RESPONSE.result: { // This is an unexpected exception that we do not know how to handle.
logger.write("[ERROR] run -> loop -> initializeUserBot -> onInizialized > Operation Failed. Aborting the process.");
bot.eventHandler.raiseEvent("Loop Finished");
callBackFunction(err);
return;
}
@@ -183,6 +193,7 @@
logger.write("[ERROR] run -> loop -> initializeUserBot -> onInizialized > Unhandled err.result received. -> err.result = " + err.result);
logger.write("[ERROR] run -> loop -> initializeUserBot -> onInizialized > Unhandled err.result received. -> err.message = " + err.message);
bot.eventHandler.raiseEvent("Loop Finished");
callBackFunction(global.DEFAULT_FAIL_RESPONSE);
return;
}
@@ -190,12 +201,14 @@
} catch (err) {
logger.write("[ERROR] run -> loop -> initializeUserBot -> onInizialized -> err = " + err.message);
bot.eventHandler.raiseEvent("Loop Finished");
callBackFunction(err);
}
}
} catch (err) {
logger.write("[ERROR] run -> loop -> initializeUserBot -> err = " + err.message);
bot.eventHandler.raiseEvent("Loop Finished");
callBackFunction(err);
}
}
@@ -229,6 +242,7 @@
}
case global.DEFAULT_FAIL_RESPONSE.result: { // This is an unexpected exception that we do not know how to handle.
logger.write("[ERROR] run -> loop -> startUserBot -> onFinished > Operation Failed. Aborting the process.");
bot.eventHandler.raiseEvent("Loop Finished");
callBackFunction(err);
return;
}
@@ -249,16 +263,19 @@
}
case "Month before it is needed.": {
logger.write("[WARN] run -> loop -> startUserBot -> onFinished > Month before it is needed. This Loop will be terminated.");
bot.eventHandler.raiseEvent("Loop Finished");
callBackFunction(global.DEFAULT_OK_RESPONSE);
return;
}
case "Month fully processed.": {
logger.write("[WARN] run -> loop -> startUserBot -> onFinished > Month fully processed. This Loop will be terminated.");
bot.eventHandler.raiseEvent("Loop Finished");
callBackFunction(global.DEFAULT_OK_RESPONSE);
return;
}
case "End of the month reached.": {
logger.write("[WARN] run -> loop -> startUserBot -> onFinished > End of the month reached. This Loop will be terminated.");
bot.eventHandler.raiseEvent("Loop Finished");
callBackFunction(global.DEFAULT_OK_RESPONSE);
return;
}
@@ -270,6 +287,7 @@
}
default: {
logger.write("[ERROR] run -> loop -> startUserBot -> onFinished > Unhandled custom response received. -> err.message = " + err.message);
bot.eventHandler.raiseEvent("Loop Finished");
callBackFunction(err);
return;
}
@@ -279,6 +297,7 @@
logger.write("[ERROR] run -> loop -> startUserBot -> onFinished > Unhandled err.result received. -> err.result = " + err.result);
logger.write("[ERROR] run -> loop -> startUserBot -> onFinished > Unhandled err.result received. -> err.message = " + err.message);
bot.eventHandler.raiseEvent("Loop Finished");
callBackFunction(global.DEFAULT_FAIL_RESPONSE);
return;
}
@@ -286,18 +305,21 @@
} catch (err) {
logger.write("[ERROR] run -> loop -> startUserBot -> onFinished -> err = " + err.message);
bot.eventHandler.raiseEvent("Loop Finished");
callBackFunction(err);
}
}
} catch (err) {
logger.write("[ERROR] run -> loop -> startUserBot -> err = " + err.message);
bot.eventHandler.raiseEvent("Loop Finished");
callBackFunction(err);
}
}
} catch (err) {
logger.write("[ERROR] run -> loop -> err = " + err.message);
bot.eventHandler.raiseEvent("Loop Finished");
callBackFunction(err);
}
}
@@ -313,6 +335,7 @@
if (bot.runAtFixedInterval === true) { intervalHandle.clearInterval();}
if (FULL_LOG === true) { logger.write("[INFO] run -> loopControl -> Stopping the Loop Gracefully. See you next time! :-)"); }
bot.eventHandler.raiseEvent("Loop Finished");
callBackFunction(global.DEFAULT_OK_RESPONSE);
return;
@@ -324,24 +347,29 @@
case 'Normal': {
if (bot.runAtFixedInterval === true) {
if (FULL_LOG === true) { logger.write("[INFO] run -> loopControl -> Fixed Interval Normal exit point reached."); }
bot.eventHandler.raiseEvent("Loop Finished");
return;
} else {
if (FULL_LOG === true) { logger.write("[INFO] run -> loopControl -> Restarting Loop in " + (processConfig.normalWaitTime / 1000) + " seconds."); }
bot.eventHandler.raiseEvent("Loop Finished");
setTimeout(loop, processConfig.normalWaitTime);
}
}
break;
case 'Retry': {
if (FULL_LOG === true) { logger.write("[INFO] run -> loopControl -> Restarting Loop in " + (processConfig.retryWaitTime / 1000) + " seconds."); }
bot.eventHandler.raiseEvent("Loop Finished");
setTimeout(loop, processConfig.retryWaitTime);
}
break;
case 'Sleep': {
if (bot.runAtFixedInterval === true) {
if (FULL_LOG === true) { logger.write("[INFO] run -> loopControl -> Fixed Interval Sleep exit point reached."); }
bot.eventHandler.raiseEvent("Loop Finished");
return;
} else {
if (FULL_LOG === true) { logger.write("[INFO] run -> loopControl -> Restarting Loop in " + (processConfig.sleepWaitTime / 60000) + " minutes."); }
bot.eventHandler.raiseEvent("Loop Finished");
setTimeout(loop, processConfig.sleepWaitTime);
}
}
@@ -349,9 +377,11 @@
case 'Coma': {
if (bot.runAtFixedInterval === true) {
if (FULL_LOG === true) { logger.write("[INFO] run -> loopControl -> Fixed Interval Coma exit point reached."); }
bot.eventHandler.raiseEvent("Loop Finished");
return;
} else {
if (FULL_LOG === true) { logger.write("[INFO] run -> loopControl -> Restarting Loop in " + (processConfig.comaWaitTime / 3600000) + " hours."); }
bot.eventHandler.raiseEvent("Loop Finished");
setTimeout(loop, processConfig.comaWaitTime);
}
}
@@ -369,16 +399,17 @@
return JSON.parse(global.PLATFORM_CONFIG.stopGracefully);
}
catch (err) {
const logText = "[ERROR] 'readConfig' - ERROR : " + err.message;
console.log(logText);
return;
logger.write("[ERROR] run -> shallWeStop -> err = " + err.message);
bot.eventHandler.raiseEvent("Loop Finished");
callBackFunction(global.DEFAULT_FAIL_RESPONSE);
}
}
}
catch (err) {
logger.write("[ERROR] run -> err = " + err.message);
bot.eventHandler.raiseEvent("Loop Finished");
callBackFunction(global.DEFAULT_FAIL_RESPONSE);
}
}
};
+1
View File
@@ -18,6 +18,7 @@ exports.newFileStorage = function newFileStorage(BOT) {
const logger = DEBUG_MODULE.newDebugLog();
logger.fileName = MODULE_NAME;
logger.bot = bot;
logger.initialize();
const shareName = 'data';
let dataOwner;
+34 -4
View File
@@ -9,11 +9,15 @@
let USER_BOT_MODULE;
let COMMONS_MODULE;
const EVENT_HANDLER_MODULE = require(ROOT_DIR + 'EventHandler');
bot.eventHandler = EVENT_HANDLER_MODULE.newEventHandler();
const DEBUG_MODULE = require(ROOT_DIR + 'Debug Log');
const logger = DEBUG_MODULE.newDebugLog();
logger.fileName = MODULE_NAME;
logger.bot = bot;
logger.forceLoopSplit = true;
logger.initialize();
let thisObject = {
initialize: initialize,
@@ -42,6 +46,7 @@
} catch (err) {
logger.write("[ERROR] initialize -> err = " + err.message);
bot.eventHandler.raiseEvent("Loop Finished");
callBackFunction(global.DEFAULT_FAIL_RESPONSE);
}
}
@@ -112,6 +117,8 @@
}
case global.DEFAULT_FAIL_RESPONSE.result: { // This is an unexpected exception that we do not know how to handle.
logger.write("[ERROR] run -> loop -> initializeStatusDependencies -> onInizialized -> Operation Failed. Aborting the process.");
bot.eventHandler.raiseEvent("Loop Finished");
callBackFunction(err);
return;
}
@@ -119,6 +126,7 @@
logger.write("[ERROR] run -> loop -> initializeStatusDependencies -> onInizialized -> Unhandled err.result received. -> err.result = " + err.result);
logger.write("[ERROR] run -> loop -> initializeStatusDependencies -> onInizialized -> Unhandled err.result received. -> err.message = " + err.message);
bot.eventHandler.raiseEvent("Loop Finished");
callBackFunction(global.DEFAULT_FAIL_RESPONSE);
return;
}
@@ -126,12 +134,14 @@
} catch (err) {
logger.write("[ERROR] run -> loop -> initializeStatusDependencies -> onInizialized -> err = " + err.message);
bot.eventHandler.raiseEvent("Loop Finished");
callBackFunction(err);
}
}
} catch (err) {
logger.write("[ERROR] run -> loop -> initializeStatusDependencies -> err = " + err.message);
bot.eventHandler.raiseEvent("Loop Finished");
callBackFunction(err);
}
}
@@ -166,6 +176,7 @@
}
case global.DEFAULT_FAIL_RESPONSE.result: { // This is an unexpected exception that we do not know how to handle.
logger.write("[ERROR] run -> loop -> initializeUserBot -> onInizialized -> Operation Failed. Aborting the process.");
bot.eventHandler.raiseEvent("Loop Finished");
callBackFunction(err);
return;
}
@@ -173,6 +184,7 @@
logger.write("[ERROR] run -> loop -> initializeUserBot -> onInizialized -> Unhandled err.result received. -> err.result = " + err.result);
logger.write("[ERROR] run -> loop -> initializeUserBot -> onInizialized -> Unhandled err.result received. -> err.message = " + err.message);
bot.eventHandler.raiseEvent("Loop Finished");
callBackFunction(global.DEFAULT_FAIL_RESPONSE);
return;
}
@@ -180,12 +192,14 @@
} catch (err) {
logger.write("[ERROR] run -> loop -> initializeUserBot -> onInizialized -> err = " + err.message);
bot.eventHandler.raiseEvent("Loop Finished");
callBackFunction(err);
}
}
} catch (err) {
logger.write("[ERROR] run -> loop -> initializeUserBot -> err = " + err.message);
bot.eventHandler.raiseEvent("Loop Finished");
callBackFunction(err);
}
}
@@ -219,6 +233,7 @@
}
case global.DEFAULT_FAIL_RESPONSE.result: { // This is an unexpected exception that we do not know how to handle.
logger.write("[ERROR] run -> loop -> startUserBot -> onFinished -> Operation Failed. Aborting the process.");
bot.eventHandler.raiseEvent("Loop Finished");
callBackFunction(err);
return;
}
@@ -239,16 +254,19 @@
}
case "Month before it is needed.": {
logger.write("[WARN] run -> loop -> startUserBot -> onFinished -> Month before it is needed. This Loop will be terminated.");
bot.eventHandler.raiseEvent("Loop Finished");
callBackFunction(global.DEFAULT_OK_RESPONSE);
return;
}
case "Month fully processed.": {
logger.write("[WARN] run -> loop -> startUserBot -> onFinished -> Month fully processed. This Loop will be terminated.");
bot.eventHandler.raiseEvent("Loop Finished");
callBackFunction(global.DEFAULT_OK_RESPONSE);
return;
}
case "End of the month reached.": {
logger.write("[WARN] run -> loop -> startUserBot -> onFinished -> End of the month reached. This Loop will be terminated.");
bot.eventHandler.raiseEvent("Loop Finished");
callBackFunction(global.DEFAULT_OK_RESPONSE);
return;
}
@@ -260,6 +278,7 @@
}
default: {
logger.write("[ERROR] run -> loop -> startUserBot -> onFinished -> Unhandled custom response received. -> err.message = " + err.message);
bot.eventHandler.raiseEvent("Loop Finished");
callBackFunction(err);
return;
}
@@ -269,6 +288,7 @@
logger.write("[ERROR] run -> loop -> startUserBot -> onFinished -> Unhandled err.result received. -> err.result = " + err.result);
logger.write("[ERROR] run -> loop -> startUserBot -> onFinished -> Unhandled err.result received. -> err.message = " + err.message);
bot.eventHandler.raiseEvent("Loop Finished");
callBackFunction(global.DEFAULT_FAIL_RESPONSE);
return;
}
@@ -276,18 +296,21 @@
} catch (err) {
logger.write("[ERROR] run -> loop -> startUserBot -> onFinished -> err = " + err.message);
bot.eventHandler.raiseEvent("Loop Finished");
callBackFunction(err);
}
}
} catch (err) {
logger.write("[ERROR] run -> loop -> startUserBot -> err = " + err.message);
bot.eventHandler.raiseEvent("Loop Finished");
callBackFunction(err);
}
}
} catch (err) {
logger.write("[ERROR] run -> loop -> err = " + err.message);
bot.eventHandler.raiseEvent("Loop Finished");
callBackFunction(err);
}
}
@@ -301,6 +324,8 @@
if (shallWeStop() === true) {
if (FULL_LOG === true) { logger.write("[INFO] run -> loopControl -> Stopping the Loop Gracefully. See you next time! :-)"); }
bot.eventHandler.raiseEvent("Loop Finished");
callBackFunction(global.DEFAULT_OK_RESPONSE);
return;
@@ -311,21 +336,25 @@
switch (nextWaitTime) {
case 'Normal': {
if (FULL_LOG === true) { logger.write("[INFO] run -> loopControl -> Restarting Loop in " + (processConfig.normalWaitTime / 1000) + " seconds."); }
bot.eventHandler.raiseEvent("Loop Finished");
setTimeout(loop, processConfig.normalWaitTime);
}
break;
case 'Retry': {
if (FULL_LOG === true) { logger.write("[INFO] run -> loopControl -> Restarting Loop in " + (processConfig.retryWaitTime / 1000) + " seconds."); }
bot.eventHandler.raiseEvent("Loop Finished");
setTimeout(loop, processConfig.retryWaitTime);
}
break;
case 'Sleep': {
if (FULL_LOG === true) { logger.write("[INFO] run -> loopControl -> Restarting Loop in " + (processConfig.sleepWaitTime / 60000) + " minutes."); }
bot.eventHandler.raiseEvent("Loop Finished");
setTimeout(loop, processConfig.sleepWaitTime);
}
break;
case 'Coma': {
if (FULL_LOG === true) { logger.write("[INFO] run -> loopControl -> Restarting Loop in " + (processConfig.comaWaitTime / 3600000) + " hours."); }
bot.eventHandler.raiseEvent("Loop Finished");
setTimeout(loop, processConfig.comaWaitTime);
}
break;
@@ -342,16 +371,17 @@
return JSON.parse(global.PLATFORM_CONFIG.stopGracefully);
}
catch (err) {
const logText = "[ERROR] 'readConfig' - ERROR : " + err.message;
console.log(logText);
return;
logger.write("[ERROR] run -> shallWeStop -> err = " + err.message);
bot.eventHandler.raiseEvent("Loop Finished");
callBackFunction(global.DEFAULT_FAIL_RESPONSE);
}
}
}
catch (err) {
logger.write("[ERROR] run -> err = " + err.message);
bot.eventHandler.raiseEvent("Loop Finished");
callBackFunction(global.DEFAULT_FAIL_RESPONSE);
}
}
};
+1
View File
@@ -32,6 +32,7 @@
<Compile Include="Data Set.js">
<SubType>Code</SubType>
</Compile>
<Compile Include="EventHandler.js" />
<Compile Include="Status Dependencies.js">
<SubType>Code</SubType>
</Compile>
+1
View File
@@ -17,6 +17,7 @@
const logger = DEBUG_MODULE.newDebugLog();
logger.fileName = MODULE_NAME;
logger.bot = bot;
logger.initialize();
return thisObject;
+6 -4
View File
@@ -13,6 +13,12 @@
const MODULE_NAME = "Status Report";
let bot = BOT;
const logger = DEBUG_MODULE.newDebugLog();
logger.bot = bot;
logger.initialize();
let thisObject = {
file: undefined, // Here we have the JSON object representing the file content.
initialize: initialize,
@@ -22,12 +28,8 @@
verifyMarketComplete: verifyMarketComplete
};
let bot = BOT;
let owner; // This is the bot owner of the Status Report. Only owners can save the report and override the existing content.
const logger = DEBUG_MODULE.newDebugLog();
logger.bot = bot;
/* Utilities needed. */
let utilities = UTILITIES.newUtilities(bot);
+52 -4
View File
@@ -9,11 +9,15 @@
let USER_BOT_MODULE;
let COMMONS_MODULE;
const EVENT_HANDLER_MODULE = require(ROOT_DIR + 'EventHandler');
bot.eventHandler = EVENT_HANDLER_MODULE.newEventHandler();
const DEBUG_MODULE = require(ROOT_DIR + 'Debug Log');
const logger = DEBUG_MODULE.newDebugLog();
logger.fileName = MODULE_NAME;
logger.bot = bot;
logger.forceLoopSplit = true;
logger.initialize();
let thisObject = {
initialize: initialize,
@@ -42,6 +46,7 @@
} catch (err) {
logger.write("[ERROR] initialize -> err = " + err.message);
bot.eventHandler.raiseEvent("Loop Finished");
callBackFunction(global.DEFAULT_FAIL_RESPONSE);
}
}
@@ -119,6 +124,7 @@
if (FULL_LOG === true) { logger.write("[INFO] run -> loop -> End of Backtesting Period reached. Exiting Bot Process Loop."); }
bot.eventHandler.raiseEvent("Loop Finished");
callBackFunction(global.DEFAULT_OK_RESPONSE);
return;
}
@@ -157,6 +163,7 @@
if (FULL_LOG === true) { logger.write("[INFO] run -> loop -> End of Competition Period reached. Exiting Bot Process Loop."); }
bot.eventHandler.raiseEvent("Loop Finished");
callBackFunction(global.DEFAULT_OK_RESPONSE);
return;
}
@@ -166,6 +173,7 @@
default: {
logger.write("[ERROR] run -> loop -> Unexpected bot.runMode.");
logger.write("[ERROR] run -> loop -> bot.runMode = " + bot.runMode);
bot.eventHandler.raiseEvent("Loop Finished");
callBackFunction(global.DEFAULT_FAIL_RESPONSE);
return;
}
@@ -214,6 +222,7 @@
}
case global.DEFAULT_FAIL_RESPONSE.result: { // This is an unexpected exception that we do not know how to handle.
logger.write("[ERROR] run -> loop -> initializeStatusDependencies -> onInizialized -> Operation Failed. Aborting the process.");
bot.eventHandler.raiseEvent("Loop Finished");
callBackFunction(err);
return;
}
@@ -221,6 +230,7 @@
logger.write("[ERROR] run -> loop -> initializeStatusDependencies -> onInizialized -> Unhandled err.result received. -> err.result = " + err.result);
logger.write("[ERROR] run -> loop -> initializeStatusDependencies -> onInizialized -> Unhandled err.result received. -> err.message = " + err.message);
bot.eventHandler.raiseEvent("Loop Finished");
callBackFunction(global.DEFAULT_FAIL_RESPONSE);
return;
}
@@ -228,12 +238,14 @@
} catch (err) {
logger.write("[ERROR] run -> loop -> initializeStatusDependencies -> onInizialized -> err = " + err.message);
bot.eventHandler.raiseEvent("Loop Finished");
callBackFunction(err);
}
}
} catch (err) {
logger.write("[ERROR] run -> loop -> initializeStatusDependencies -> err = " + err.message);
bot.eventHandler.raiseEvent("Loop Finished");
callBackFunction(err);
}
}
@@ -268,6 +280,7 @@
}
case global.DEFAULT_FAIL_RESPONSE.result: { // This is an unexpected exception that we do not know how to handle.
logger.write("[ERROR] run -> loop -> initializeDataDependencies -> onInizialized -> Operation Failed. Aborting the process.");
bot.eventHandler.raiseEvent("Loop Finished");
callBackFunction(err);
return;
}
@@ -275,6 +288,7 @@
logger.write("[ERROR] run -> loop -> initializeDataDependencies -> onInizialized -> Unhandled err.result received. -> err.result = " + err.result);
logger.write("[ERROR] run -> loop -> initializeDataDependencies -> onInizialized -> Unhandled err.result received. -> err.message = " + err.message);
bot.eventHandler.raiseEvent("Loop Finished");
callBackFunction(global.DEFAULT_FAIL_RESPONSE);
return;
}
@@ -282,12 +296,14 @@
} catch (err) {
logger.write("[ERROR] run -> loop -> initializeDataDependencies -> onInizialized -> err = " + err.message);
bot.eventHandler.raiseEvent("Loop Finished");
callBackFunction(err);
}
}
} catch (err) {
logger.write("[ERROR] run -> loop -> initializeDataDependencies -> err = " + err.message);
bot.eventHandler.raiseEvent("Loop Finished");
callBackFunction(err);
}
}
@@ -321,6 +337,7 @@
}
case global.DEFAULT_FAIL_RESPONSE.result: { // This is an unexpected exception that we do not know how to handle.
logger.write("[ERROR] run -> loop -> initializeContext -> onInizialized -> Operation Failed. Aborting the process.");
bot.eventHandler.raiseEvent("Loop Finished");
callBackFunction(err);
return;
}
@@ -328,6 +345,7 @@
logger.write("[ERROR] run -> loop -> initializeContext -> onInizialized -> Unhandled err.result received. -> err.result = " + err.result);
logger.write("[ERROR] run -> loop -> initializeContext -> onInizialized -> Unhandled err.result received. -> err.message = " + err.message);
bot.eventHandler.raiseEvent("Loop Finished");
callBackFunction(global.DEFAULT_FAIL_RESPONSE);
return;
}
@@ -335,12 +353,14 @@
} catch (err) {
logger.write("[ERROR] run -> loop -> initializeContext -> onInizialized -> err = " + err.message);
bot.eventHandler.raiseEvent("Loop Finished");
callBackFunction(err);
}
}
} catch (err) {
logger.write("[ERROR] run -> loop -> initializeContext -> err = " + err.message);
bot.eventHandler.raiseEvent("Loop Finished");
callBackFunction(err);
}
}
@@ -375,6 +395,7 @@
}
case global.DEFAULT_FAIL_RESPONSE.result: { // This is an unexpected exception that we do not know how to handle.
logger.write("[ERROR] run -> loop -> initializeExchangeAPI -> onInizialized -> Operation Failed. Aborting the process.");
bot.eventHandler.raiseEvent("Loop Finished");
callBackFunction(err);
return;
}
@@ -382,6 +403,7 @@
logger.write("[ERROR] run -> loop -> initializeExchangeAPI -> onInizialized -> Unhandled err.result received. -> err.result = " + err.result);
logger.write("[ERROR] run -> loop -> initializeExchangeAPI -> onInizialized -> Unhandled err.result received. -> err.message = " + err.message);
bot.eventHandler.raiseEvent("Loop Finished");
callBackFunction(global.DEFAULT_FAIL_RESPONSE);
return;
}
@@ -389,12 +411,14 @@
} catch (err) {
logger.write("[ERROR] run -> loop -> initializeContext -> onInizialized -> onInizialized -> err = " + err.message);
bot.eventHandler.raiseEvent("Loop Finished");
callBackFunction(err);
}
}
} catch (err) {
logger.write("[ERROR] run -> loop -> initializeExchangeAPI -> err = " + err.message);
bot.eventHandler.raiseEvent("Loop Finished");
callBackFunction(err);
}
}
@@ -428,6 +452,7 @@
}
case global.DEFAULT_FAIL_RESPONSE.result: { // This is an unexpected exception that we do not know how to handle.
logger.write("[ERROR] run -> loop -> initializeAssistant -> onInizialized -> Operation Failed. Aborting the process.");
bot.eventHandler.raiseEvent("Loop Finished");
callBackFunction(err);
return;
}
@@ -435,6 +460,7 @@
logger.write("[ERROR] run -> loop -> initializeAssistant -> onInizialized -> Unhandled err.result received. -> err.result = " + err.result);
logger.write("[ERROR] run -> loop -> initializeAssistant -> onInizialized -> Unhandled err.result received. -> err.message = " + err.message);
bot.eventHandler.raiseEvent("Loop Finished");
callBackFunction(global.DEFAULT_FAIL_RESPONSE);
return;
}
@@ -442,12 +468,14 @@
} catch (err) {
logger.write("[ERROR] run -> loop -> initializeAssistant -> onInizialized -> err = " + err.message);
bot.eventHandler.raiseEvent("Loop Finished");
callBackFunction(err);
}
}
} catch (err) {
logger.write("[ERROR] run -> loop -> initializeAssistant -> err = " + err.message);
bot.eventHandler.raiseEvent("Loop Finished");
callBackFunction(err);
}
}
@@ -482,6 +510,7 @@
}
case global.DEFAULT_FAIL_RESPONSE.result: { // This is an unexpected exception that we do not know how to handle.
logger.write("[ERROR] run -> loop -> initializeUserBot -> onInizialized -> Operation Failed. Aborting the process.");
bot.eventHandler.raiseEvent("Loop Finished");
callBackFunction(err);
return;
}
@@ -489,6 +518,7 @@
logger.write("[ERROR] run -> loop -> initializeUserBot -> onInizialized -> Unhandled err.result received. -> err.result = " + err.result);
logger.write("[ERROR] run -> loop -> initializeUserBot -> onInizialized -> Unhandled err.result received. -> err.message = " + err.message);
bot.eventHandler.raiseEvent("Loop Finished");
callBackFunction(global.DEFAULT_FAIL_RESPONSE);
return;
}
@@ -496,12 +526,14 @@
} catch (err) {
logger.write("[ERROR] run -> loop -> initializeUserBot -> onInizialized -> err = " + err.message);
bot.eventHandler.raiseEvent("Loop Finished");
callBackFunction(err);
}
}
} catch (err) {
logger.write("[ERROR] run -> loop -> initializeUserBot -> err = " + err.message);
bot.eventHandler.raiseEvent("Loop Finished");
callBackFunction(err);
}
}
@@ -534,6 +566,7 @@
}
case global.DEFAULT_FAIL_RESPONSE.result: { // This is an unexpected exception that we do not know how to handle.
logger.write("[ERROR] run -> loop -> startUserBot -> onFinished -> Operation Failed. Aborting the process.");
bot.eventHandler.raiseEvent("Loop Finished");
callBackFunction(err);
return;
}
@@ -541,6 +574,7 @@
logger.write("[ERROR] run -> loop -> startUserBot -> onFinished -> Unhandled err.result received. -> err.result = " + err.result);
logger.write("[ERROR] run -> loop -> startUserBot -> onFinished -> Unhandled err.result received. -> err.message = " + err.message);
bot.eventHandler.raiseEvent("Loop Finished");
callBackFunction(global.DEFAULT_FAIL_RESPONSE);
return;
}
@@ -548,12 +582,14 @@
} catch (err) {
logger.write("[ERROR] run -> loop -> startUserBot -> onFinished -> err = " + err.message);
bot.eventHandler.raiseEvent("Loop Finished");
callBackFunction(err);
}
}
} catch (err) {
logger.write("[ERROR] run -> loop -> startUserBot -> err = " + err.message);
bot.eventHandler.raiseEvent("Loop Finished");
callBackFunction(err);
}
}
@@ -581,11 +617,13 @@
}
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] run -> loop -> saveContext -> onFinished -> Can not retry at this point.");
bot.eventHandler.raiseEvent("Loop Finished");
callBackFunction(global.DEFAULT_FAIL_RESPONSE);
return;
}
case global.DEFAULT_FAIL_RESPONSE.result: { // This is an unexpected exception that we do not know how to handle.
logger.write("[ERROR] run -> loop -> saveContext -> onFinished -> Operation Failed. Aborting the process.");
bot.eventHandler.raiseEvent("Loop Finished");
callBackFunction(err);
return;
}
@@ -593,6 +631,7 @@
logger.write("[ERROR] run -> loop -> saveContext -> onFinished -> Unhandled err.result received. -> err.result = " + err.result);
logger.write("[ERROR] run -> loop -> saveContext -> onFinished -> Unhandled err.result received. -> err.message = " + err.message);
bot.eventHandler.raiseEvent("Loop Finished");
callBackFunction(global.DEFAULT_FAIL_RESPONSE);
return;
}
@@ -600,18 +639,21 @@
} catch (err) {
logger.write("[ERROR] run -> loop -> saveContext -> onFinished -> err = " + err.message);
bot.eventHandler.raiseEvent("Loop Finished");
callBackFunction(err);
}
}
} catch (err) {
logger.write("[ERROR] run -> loop -> saveContext -> err = " + err.message);
bot.eventHandler.raiseEvent("Loop Finished");
callBackFunction(err);
}
}
} catch (err) {
logger.write("[ERROR] run -> loop -> err = " + err.message);
bot.eventHandler.raiseEvent("Loop Finished");
callBackFunction(err);
}
}
@@ -625,6 +667,7 @@
if (shallWeStop() === true) {
if (FULL_LOG === true) { logger.write("[INFO] run -> loopControl -> Stopping the Loop Gracefully. See you next time! :-)"); }
bot.eventHandler.raiseEvent("Loop Finished");
callBackFunction(global.DEFAULT_OK_RESPONSE);
return;
@@ -635,21 +678,25 @@
switch (nextWaitTime) {
case 'Normal': {
if (FULL_LOG === true) { logger.write("[INFO] run -> loopControl -> Restarting Loop in " + (processConfig.normalWaitTime / 1000) + " seconds."); }
bot.eventHandler.raiseEvent("Loop Finished");
setTimeout(loop, processConfig.normalWaitTime);
}
break;
case 'Retry': {
if (FULL_LOG === true) { logger.write("[INFO] run -> loopControl -> Restarting Loop in " + (processConfig.retryWaitTime / 1000) + " seconds."); }
bot.eventHandler.raiseEvent("Loop Finished");
setTimeout(loop, processConfig.retryWaitTime);
}
break;
case 'Sleep': {
if (FULL_LOG === true) { logger.write("[INFO] run -> loopControl -> Restarting Loop in " + (processConfig.sleepWaitTime / 60000) + " minutes."); }
bot.eventHandler.raiseEvent("Loop Finished");
setTimeout(loop, processConfig.sleepWaitTime);
}
break;
case 'Coma': {
if (FULL_LOG === true) { logger.write("[INFO] run -> loopControl -> Restarting Loop in " + (processConfig.comaWaitTime / 3600000) + " hours."); }
bot.eventHandler.raiseEvent("Loop Finished");
setTimeout(loop, processConfig.comaWaitTime);
}
break;
@@ -666,16 +713,17 @@
return JSON.parse(global.PLATFORM_CONFIG.stopGracefully);
}
catch (err) {
const logText = "[ERROR] 'readConfig' - ERROR : " + err.message;
console.log(logText);
return;
logger.write("[ERROR] run -> shallWeStop -> err = " + err.message);
bot.eventHandler.raiseEvent("Loop Finished");
callBackFunction(global.DEFAULT_FAIL_RESPONSE);
}
}
}
catch (err) {
logger.write("[ERROR] run -> err = " + err.message);
bot.eventHandler.raiseEvent("Loop Finished");
callBackFunction(global.DEFAULT_FAIL_RESPONSE);
}
}
};
+1
View File
@@ -13,6 +13,7 @@ exports.newUtilities = function newUtilities(BOT) {
const logger = DEBUG_MODULE.newDebugLog();
logger.fileName = MODULE_NAME;
logger.bot = bot;
logger.initialize();
let utilities = {
pad: pad,
-3
View File
@@ -10,9 +10,6 @@
"license": "ISC",
"dependencies": {
"azure-storage": "^2.8.2",
"node-uuid": "^1.4.8",
"nonce": "^1.0.4",
"request": "^2.85.0",
"rimraf": "^2.6.2"
}
}