statusDependencies at Trading Main Loop Implemented

This commit is contained in:
Luis Fernando Molina committed 2018-04-15 13:43:00 +02:00
1 parent 8c94ce01ce
commit 43e1717cdc
6 files changed
+220 -49

No files matched your search

Binary file not shown.
+139 -1
View File
@@ -1 +1,139 @@

exports.newDataDependencies = function newDataDependencies(BOT, DEBUG_MODULE, STATUS_REPORT, BLOB_STORAGE, UTILITIES) {
const FULL_LOG = true;
const LOG_FILE_CONTENT = false;
const MODULE_NAME = "Data Dependencies";
let thisObject = {
statusReports: new Map(),
initialize: initialize,
keys: []
};
let bot = BOT;
let ownerBot; // 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.fileName = MODULE_NAME;
logger.bot = bot;
return thisObject;
function initialize(pDataDependenciesConfig, pMonth, pYear, callBackFunction) {
try {
if (FULL_LOG === true) { logger.write("[INFO] initialize -> Entering function."); }
/*
For each dependency declared at the bot config, we will initialize the status report, and load it as part of this initialization process.
*/
let alreadyCalledBack = false;
let loadCount = 0;
for (let i = 0; i < pDataDependenciesConfig.length; i++) {
let statusReportModule = STATUS_REPORT.newStatusReport(BOT, DEBUG_MODULE, BLOB_STORAGE, UTILITIES);
statusReportModule.initialize(pDataDependenciesConfig[i], pMonth, pYear, onInitilized);
function onInitilized(err) {
if (err.result !== global.DEFAULT_OK_RESPONSE.result) {
logger.write("[ERROR] initialize -> onInitilized -> err = " + err.message);
alreadyCalledBack = true;
callBackFunction(err);
return;
}
statusReportModule.load(onLoad);
}
function onLoad(err) {
try {
statusReportModule.status = err.message;
switch (err.message) {
case global.DEFAULT_OK_RESPONSE.message: {
logger.write("[INFO] initialize -> onLoad -> Execution finished well. -> bot = " + pDataDependenciesConfig[i].bot);
logger.write("[INFO] initialize -> onLoad -> Execution finished well. -> process = " + pDataDependenciesConfig[i].process);
addReport();
return;
}
case "Status Report was never created.": {
logger.write("[WARN] initialize -> onLoad -> err.message = " + err.message);
logger.write("[WARN] initialize -> onLoad -> Report Not Found. -> bot = " + pDataDependenciesConfig[i].bot);
logger.write("[WARN] initialize -> onLoad -> Report Not Found. -> process = " + pDataDependenciesConfig[i].process);
addReport();
return;
}
case "Status Report is corrupt.": {
logger.write("[WARN] initialize -> onLoad -> err.message = " + err.message);
logger.write("[WARN] initialize -> onLoad -> Report Not Found. -> bot = " + pDataDependenciesConfig[i].bot);
logger.write("[WARN] initialize -> onLoad -> Report Not Found. -> process = " + pDataDependenciesConfig[i].process);
addReport();
return;
}
default:
{
logger.write("[ERROR] initialize -> onLoad -> Operation Failed.");
if (alreadyCalledBack === false) {
alreadyCalledBack = true;
callBackFunction(err);
}
return;
}
}
}
catch (err) {
logger.write("[ERROR] initialize -> onLoad -> err = " + err.message);
callBackFunction(global.DEFAULT_FAIL_RESPONSE);
}
}
function addReport() {
if (FULL_LOG === true) { logger.write("[INFO] initialize -> addReport -> Entering function."); }
loadCount++;
let key;
if (pDataDependenciesConfig[i].dataSetSection === "Month") {
key = pDataDependenciesConfig[i].devTeam + "-" + pDataDependenciesConfig[i].bot + "-" + pDataDependenciesConfig[i].process + "-" + pDataDependenciesConfig[i].dataSetVersion + "-" + pYear + "-" + pMonth;
} else {
key = pDataDependenciesConfig[i].devTeam + "-" + pDataDependenciesConfig[i].bot + "-" + pDataDependenciesConfig[i].process + "-" + pDataDependenciesConfig[i].dataSetVersion;
}
thisObject.keys.push(key);
thisObject.statusReports.set(key, statusReportModule);
if (FULL_LOG === true) { logger.write("[INFO] initialize -> addReport -> Report added to Map. -> key = " + key); }
if (loadCount === pDataDependenciesConfig.length) {
if (alreadyCalledBack === false) {
callBackFunction(global.DEFAULT_OK_RESPONSE);
return;
}
}
}
}
} catch (err) {
logger.write("[ERROR] initialize -> err = " + err.message);
callBackFunction(global.DEFAULT_FAIL_RESPONSE);
}
}
};
+11 -11
View File
@@ -67,7 +67,7 @@
const DEBUG_MODULE = require(ROOT_DIR + 'Debug Log');
const STATUS_REPORT = require(ROOT_DIR + 'Status Report');
const POLONIEX_CLIENT_MODULE = require(ROOT_DIR + 'Poloniex API Client');
const DEPENDENCIES = require(ROOT_DIR + 'Status Dependencies');
const STATUS_DEPENDENCIES = require(ROOT_DIR + 'Status 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. */
@@ -76,36 +76,36 @@
/* We will prepare first the infraestructure needed for the bot to run. There are 3 modules we need to sucessfullly initialize first. */
let userBot;
let dependencies;
let statusDependencies;
let nextWaitTime;
initializeDependencies();
initializeStatusDependencies();
function initializeDependencies() {
function initializeStatusDependencies() {
if (FULL_LOG === true) { logger.write("[INFO] run -> loop -> initializeDependencies -> Entering function."); }
if (FULL_LOG === true) { logger.write("[INFO] run -> loop -> initializeStatusDependencies -> Entering function."); }
dependencies = DEPENDENCIES.newStatusDependencies(bot, DEBUG_MODULE, STATUS_REPORT, BLOB_STORAGE, UTILITIES);
statusDependencies = STATUS_DEPENDENCIES.newStatusDependencies(bot, DEBUG_MODULE, STATUS_REPORT, BLOB_STORAGE, UTILITIES);
dependencies.initialize(processConfig.statusDependencies, pMonth, pYear, onInizialized);
statusDependencies.initialize(processConfig.statusDependencies, pMonth, pYear, onInizialized);
function onInizialized(err) {
switch (err.result) {
case global.DEFAULT_OK_RESPONSE.result: {
logger.write("[INFO] run -> loop -> initializeDependencies -> onInizialized > Execution finished well. :-)");
logger.write("[INFO] run -> loop -> initializeStatusDependencies -> 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.");
logger.write("[ERROR] run -> loop -> initializeStatusDependencies -> 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.");
logger.write("[ERROR] run -> loop -> initializeStatusDependencies -> onInizialized > Operation Failed. Aborting the process.");
callBackFunction(err);
return;
}
@@ -119,7 +119,7 @@
usertBot = USER_BOT_MODULE.newUserBot(bot, COMMONS_MODULE, UTILITIES, DEBUG_MODULE, BLOB_STORAGE, STATUS_REPORT, POLONIEX_CLIENT_MODULE);
usertBot.initialize(dependencies, pMonth, pYear, onInizialized);
usertBot.initialize(statusDependencies, pMonth, pYear, onInizialized);
function onInizialized(err) {
+11 -11
View File
@@ -67,7 +67,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 + 'Status Dependencies');
const STATUS_DEPENDENCIES = require(ROOT_DIR + 'Status 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. */
@@ -76,36 +76,36 @@
/* We will prepare first the infraestructure needed for the bot to run. There are 3 modules we need to sucessfullly initialize first. */
let userBot;
let dependencies;
let statusDependencies;
let nextWaitTime;
initializeDependencies();
initializeStatusDependencies();
function initializeDependencies() {
function initializeStatusDependencies() {
if (FULL_LOG === true) { logger.write("[INFO] run -> loop -> initializeDependencies -> Entering function."); }
if (FULL_LOG === true) { logger.write("[INFO] run -> loop -> initializeStatusDependencies -> Entering function."); }
dependencies = DEPENDENCIES.newStatusDependencies(bot, DEBUG_MODULE, STATUS_REPORT, BLOB_STORAGE, UTILITIES);
statusDependencies = STATUS_DEPENDENCIES.newStatusDependencies(bot, DEBUG_MODULE, STATUS_REPORT, BLOB_STORAGE, UTILITIES);
dependencies.initialize(processConfig.statusDependencies, pMonth, pYear, onInizialized);
statusDependencies.initialize(processConfig.statusDependencies, pMonth, pYear, onInizialized);
function onInizialized(err) {
switch (err.result) {
case global.DEFAULT_OK_RESPONSE.result: {
logger.write("[INFO] run -> loop -> initializeDependencies -> onInizialized > Execution finished well. :-)");
logger.write("[INFO] run -> loop -> initializeStatusDependencies -> 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.");
logger.write("[ERROR] run -> loop -> initializeStatusDependencies -> 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.");
logger.write("[ERROR] run -> loop -> initializeStatusDependencies -> onInizialized > Operation Failed. Aborting the process.");
callBackFunction(err);
return;
}
@@ -119,7 +119,7 @@
usertBot = USER_BOT_MODULE.newUserBot(bot, COMMONS_MODULE, UTILITIES, DEBUG_MODULE, BLOB_STORAGE, FILE_STORAGE);
usertBot.initialize(dependencies, pMonth, pYear, onInizialized);
usertBot.initialize(statusDependencies, pMonth, pYear, onInizialized);
function onInizialized(err) {
+14 -14
View File
@@ -3,7 +3,7 @@
const FULL_LOG = true;
const LOG_FILE_CONTENT = false;
const MODULE_NAME = "Dependencies";
const MODULE_NAME = "Status Dependencies";
let thisObject = {
statusReports: new Map(),
@@ -20,7 +20,7 @@
return thisObject;
function initialize(pDependenciesConfig, pMonth, pYear, callBackFunction) {
function initialize(pStatusDependenciesConfig, pMonth, pYear, callBackFunction) {
try {
@@ -34,11 +34,11 @@
let alreadyCalledBack = false;
let loadCount = 0;
for (let i = 0; i < pDependenciesConfig.length; i++) {
for (let i = 0; i < pStatusDependenciesConfig.length; i++) {
let statusReportModule = STATUS_REPORT.newStatusReport(BOT, DEBUG_MODULE, BLOB_STORAGE, UTILITIES);
statusReportModule.initialize(pDependenciesConfig[i], pMonth, pYear, onInitilized);
statusReportModule.initialize(pStatusDependenciesConfig[i], pMonth, pYear, onInitilized);
function onInitilized(err) {
@@ -61,8 +61,8 @@
switch (err.message) {
case global.DEFAULT_OK_RESPONSE.message: {
logger.write("[INFO] initialize -> onLoad -> Execution finished well. -> bot = " + pDependenciesConfig[i].bot);
logger.write("[INFO] initialize -> onLoad -> Execution finished well. -> process = " + pDependenciesConfig[i].process);
logger.write("[INFO] initialize -> onLoad -> Execution finished well. -> bot = " + pStatusDependenciesConfig[i].bot);
logger.write("[INFO] initialize -> onLoad -> Execution finished well. -> process = " + pStatusDependenciesConfig[i].process);
addReport();
return;
@@ -70,8 +70,8 @@
case "Status Report was never created.": {
logger.write("[WARN] initialize -> onLoad -> err.message = " + err.message);
logger.write("[WARN] initialize -> onLoad -> Report Not Found. -> bot = " + pDependenciesConfig[i].bot);
logger.write("[WARN] initialize -> onLoad -> Report Not Found. -> process = " + pDependenciesConfig[i].process);
logger.write("[WARN] initialize -> onLoad -> Report Not Found. -> bot = " + pStatusDependenciesConfig[i].bot);
logger.write("[WARN] initialize -> onLoad -> Report Not Found. -> process = " + pStatusDependenciesConfig[i].process);
addReport();
return;
}
@@ -79,8 +79,8 @@
case "Status Report is corrupt.": {
logger.write("[WARN] initialize -> onLoad -> err.message = " + err.message);
logger.write("[WARN] initialize -> onLoad -> Report Not Found. -> bot = " + pDependenciesConfig[i].bot);
logger.write("[WARN] initialize -> onLoad -> Report Not Found. -> process = " + pDependenciesConfig[i].process);
logger.write("[WARN] initialize -> onLoad -> Report Not Found. -> bot = " + pStatusDependenciesConfig[i].bot);
logger.write("[WARN] initialize -> onLoad -> Report Not Found. -> process = " + pStatusDependenciesConfig[i].process);
addReport();
return;
}
@@ -110,10 +110,10 @@
let key;
if (pDependenciesConfig[i].dataSetSection === "Month") {
key = pDependenciesConfig[i].devTeam + "-" + pDependenciesConfig[i].bot + "-" + pDependenciesConfig[i].process + "-" + pDependenciesConfig[i].dataSetVersion + "-" + pYear + "-" + pMonth;
if (pStatusDependenciesConfig[i].dataSetSection === "Month") {
key = pStatusDependenciesConfig[i].devTeam + "-" + pStatusDependenciesConfig[i].bot + "-" + pStatusDependenciesConfig[i].process + "-" + pStatusDependenciesConfig[i].dataSetVersion + "-" + pYear + "-" + pMonth;
} else {
key = pDependenciesConfig[i].devTeam + "-" + pDependenciesConfig[i].bot + "-" + pDependenciesConfig[i].process + "-" + pDependenciesConfig[i].dataSetVersion;
key = pStatusDependenciesConfig[i].devTeam + "-" + pStatusDependenciesConfig[i].bot + "-" + pStatusDependenciesConfig[i].process + "-" + pStatusDependenciesConfig[i].dataSetVersion;
}
thisObject.keys.push(key);
@@ -121,7 +121,7 @@
if (FULL_LOG === true) { logger.write("[INFO] initialize -> addReport -> Report added to Map. -> key = " + key); }
if (loadCount === pDependenciesConfig.length) {
if (loadCount === pStatusDependenciesConfig.length) {
if (alreadyCalledBack === false) {
callBackFunction(global.DEFAULT_OK_RESPONSE);
return;
+45 -12
View File
@@ -71,7 +71,8 @@
const DATASOURCE = require(ROOT_DIR + 'Datasource');
const ASSISTANT = require(ROOT_DIR + 'Assistant');
const STATUS_REPORT = require(ROOT_DIR + 'Status Report');
const DEPENDENCIES = require(ROOT_DIR + 'Status Dependencies');
const STATUS_DEPENDENCIES = require(ROOT_DIR + 'Status Dependencies');
const DATA_DEPENDENCIES = require(ROOT_DIR + 'Data 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. */
@@ -84,36 +85,68 @@
let exchangeAPI;
let assistant;
let userBot;
let dependencies;
let statusDependencies;
let dataDependencies;
let nextWaitTime;
initializeDependencies();
initializeStatusDependencies();
function initializeDependencies() {
function initializeStatusDependencies() {
if (FULL_LOG === true) { logger.write("[INFO] run -> loop -> initializeDependencies -> Entering function."); }
if (FULL_LOG === true) { logger.write("[INFO] run -> loop -> initializeStatusDependencies -> Entering function."); }
dependencies = DEPENDENCIES.newStatusDependencies(bot, DEBUG_MODULE, STATUS_REPORT, BLOB_STORAGE, UTILITIES);
statusDependencies = STATUS_DEPENDENCIES.newStatusDependencies(bot, DEBUG_MODULE, STATUS_REPORT, BLOB_STORAGE, UTILITIES);
dependencies.initialize(processConfig.statusDependencies, undefined, undefined, onInizialized);
statusDependencies.initialize(processConfig.statusDependencies, undefined, undefined, onInizialized);
function onInizialized(err) {
switch (err.result) {
case global.DEFAULT_OK_RESPONSE.result: {
logger.write("[INFO] run -> loop -> initializeDependencies -> onInizialized > Execution finished well. :-)");
initializeContext();
logger.write("[INFO] run -> loop -> initializeStatusDependencies -> onInizialized > Execution finished well. :-)");
initializeDataDependencies();
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.");
logger.write("[ERROR] run -> loop -> initializeStatusDependencies -> 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.");
logger.write("[ERROR] run -> loop -> initializeStatusDependencies -> onInizialized > Operation Failed. Aborting the process.");
callBackFunction(err);
return;
}
}
}
}
function initializeDataDependencies() {
if (FULL_LOG === true) { logger.write("[INFO] run -> loop -> initializeDataDependencies -> Entering function."); }
dataDependencies = DATA_DEPENDENCIES.newDataDependencies(bot, DEBUG_MODULE, STATUS_REPORT, BLOB_STORAGE, UTILITIES);
dataDependencies.initialize(processConfig.dataDependencies, undefined, undefined, onInizialized);
function onInizialized(err) {
switch (err.result) {
case global.DEFAULT_OK_RESPONSE.result: {
logger.write("[INFO] run -> loop -> initializeDataDependencies -> onInizialized > Execution finished well. :-)");
initializeContext();
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 -> initializeDataDependencies -> 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 -> initializeDataDependencies -> onInizialized > Operation Failed. Aborting the process.");
callBackFunction(err);
return;
}
@@ -126,7 +159,7 @@
if (FULL_LOG === true) { logger.write("[INFO] run -> loop -> initializeContext -> Entering function."); }
context = CONTEXT.newContext(bot, DEBUG_MODULE, BLOB_STORAGE, UTILITIES, STATUS_REPORT);
context.initialize(dependencies, onInizialized);
context.initialize(statusDependencies, onInizialized);
function onInizialized(err) {