Dependencies Implemented

This commit is contained in:
Luis Fernando Molina committed 2018-03-17 13:39:15 +01:00
1 parent 3ec67e1891
commit ed1c4f075f
11 files changed
+266 -52

No files matched your search

+37 -9
View File
@@ -55,6 +55,8 @@
function loop() {
try {
global.loopCointer++;
if (FULL_LOG === true) { logger.write("[INFO] run -> loop -> Entering function."); }
/* We define here all the modules that the rest of the infraestructure, including the bots themselves can consume. */
@@ -63,6 +65,7 @@
const FILE_STORAGE = require(ROOT_DIR + 'File Storage');
const DEBUG_MODULE = require(ROOT_DIR + 'Debug Log');
const STATUS_REPORT = require(ROOT_DIR + 'Status Report');
const DEPENDENCIES = require(ROOT_DIR + 'Dependencies');
/* We define the datetime for the process that we are running now. This will be the official processing time for both the infraestructure and the bot. */
@@ -74,15 +77,46 @@
let nextWaitTime;
initializeUserBot();
initializeDependencies();
function initializeDependencies() {
if (FULL_LOG === true) { logger.write("[INFO] run -> loop -> initializeDependencies -> Entering function."); }
dependencies = DEPENDENCIES.newDependencies(bot, DEBUG_MODULE, STATUS_REPORT, FILE_STORAGE, UTILITIES);
dependencies.initialize(processConfig.dependencies, onInizialized);
function onInizialized(err) {
switch (err.result) {
case global.DEFAULT_OK_RESPONSE.result: {
logger.write("[INFO] run -> loop -> initializeDependencies -> onInizialized > Execution finished well. :-)");
initializeUserBot();
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] run -> loop -> initializeDependencies -> onInizialized > Retry Later. Requesting Execution Retry.");
nextWaitTime = 'Retry';
loopControl(nextWaitTime);
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 -> initializeDependencies -> onInizialized > Operation Failed. Aborting the process.");
callBackFunction(err);
return;
}
}
}
}
function initializeUserBot() {
if (FULL_LOG === true) { logger.write("[INFO] run -> loop -> initializeUserBot -> Entering function."); }
usertBot = USER_BOT_MODULE.newUserBot(bot, COMMONS_MODULE, UTILITIES, DEBUG_MODULE, FILE_STORAGE, STATUS_REPORT);
usertBot = USER_BOT_MODULE.newUserBot(bot, COMMONS_MODULE, UTILITIES, DEBUG_MODULE, FILE_STORAGE);
usertBot.initialize(undefined, undefined, onInizialized);
usertBot.initialize(dependencies, onInizialized, undefined, undefined);
function onInizialized(err) {
@@ -92,20 +126,17 @@
startUserBot();
return;
}
break;
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 -> initializeUserBot -> onInizialized > Retry Later. Requesting Execution Retry.");
nextWaitTime = 'Retry';
loopControl(nextWaitTime);
return;
}
break;
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.");
callBackFunction(err);
return;
}
break;
}
}
}
@@ -125,20 +156,17 @@
loopControl(nextWaitTime);
return;
}
break;
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 -> startUserBot -> onFinished > Retry Later. Requesting Execution Retry.");
nextWaitTime = 'Retry';
loopControl(nextWaitTime);
return;
}
break;
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.");
callBackFunction(err);
return;
}
break;
}
}
}