Concept of Multiple Instances of a Process Removed

This commit is contained in:
Luis Fernando Molina committed 2020-02-03 17:58:41 +01:00
1 parent 566b0331c0
commit 9651ccf15d
7 files changed
+38 -613

No files matched your search

+5 -89
View File
@@ -85,7 +85,7 @@
}
}
function run(pMonth, pYear, callBackFunction) {
function run(callBackFunction) {
try {
@@ -145,7 +145,7 @@
/* High level log entry */
console.log(new Date().toISOString() + " " + pad(bot.codeName, 20) + " " + pad(bot.process, 30) + " " + pad(pMonth, 2) + "/" + pad(pYear, 4)
console.log(new Date().toISOString() + " " + pad(bot.codeName, 20) + " " + pad(bot.process, 30)
+ " Entered into Main Loop # " + pad(Number(bot.loopCounter), 8));
/* We will prepare first the infraestructure needed for the bot to run. There are 3 modules we need to sucessfullly initialize first. */
@@ -169,7 +169,7 @@
processExecutionEvents = PROCESS_EXECUTION_EVENTS.newProcessExecutionEvents(bot, logger)
processExecutionEvents.initialize(pMonth, pYear, onInizialized);
processExecutionEvents.initialize(onInizialized);
function onInizialized(err) {
@@ -317,7 +317,7 @@
statusDependencies = STATUS_DEPENDENCIES.newStatusDependencies(bot, logger, STATUS_REPORT, UTILITIES);
statusDependencies.initialize(pMonth, pYear, onInizialized);
statusDependencies.initialize(onInizialized);
function onInizialized(err) {
@@ -496,7 +496,7 @@
usertBot = USER_BOT_MODULE.newUserBot(bot, logger, COMMONS_MODULE, UTILITIES, fileStorage);
usertBot.initialize(statusDependencies, pMonth, pYear, onInizialized);
usertBot.initialize(statusDependencies, onInizialized);
function onInizialized(err) {
@@ -530,18 +530,6 @@
case global.CUSTOM_OK_RESPONSE.result: {
switch (err.message) {
case "Too far in the future.": {
logger.write(MODULE_NAME, "[WARN] run -> loop -> initializeUserBot -> onInizialized > Too far in the future. This Loop will enter in coma.");
nextWaitTime = 'Coma';
loopControl(nextWaitTime);
return;
}
case "Not needed now, but soon.": {
logger.write(MODULE_NAME, "[WARN] run -> loop -> initializeUserBot -> onInizialized > Not needed now, but soon. This Loop will continue with Normal wait time.");
nextWaitTime = 'Normal';
loopControl(nextWaitTime);
return;
}
default: {
logger.write(MODULE_NAME, "[ERROR] run -> loop -> initializeUserBot -> onInizialized > Unhandled custom response received. -> err = " + err.message);
logger.persist();
@@ -642,36 +630,6 @@
loopControl(nextWaitTime);
return;
}
case "Month before it is needed.": {
logger.write(MODULE_NAME, "[WARN] run -> loop -> startUserBot -> onFinished -> Month before it is needed. This Loop will be terminated.");
logger.persist();
clearInterval(fixedTimeLoopIntervalHandle);
clearTimeout(nextLoopTimeoutHandle);
clearTimeout(checkLoopHealthHandle);
bot.enableCheckLoopHealth = false;
callBackFunction(global.DEFAULT_OK_RESPONSE);
return;
}
case "Month fully processed.": {
logger.write(MODULE_NAME, "[WARN] run -> loop -> startUserBot -> onFinished -> Month fully processed. This Loop will be terminated.");
logger.persist();
clearInterval(fixedTimeLoopIntervalHandle);
clearTimeout(nextLoopTimeoutHandle);
clearTimeout(checkLoopHealthHandle);
bot.enableCheckLoopHealth = false;
callBackFunction(global.DEFAULT_OK_RESPONSE);
return;
}
case "End of the month reached.": {
logger.write(MODULE_NAME, "[WARN] run -> loop -> startUserBot -> onFinished -> End of the month reached. This Loop will be terminated.");
logger.persist();
clearInterval(fixedTimeLoopIntervalHandle);
clearTimeout(nextLoopTimeoutHandle);
clearTimeout(checkLoopHealthHandle);
bot.enableCheckLoopHealth = false;
callBackFunction(global.DEFAULT_OK_RESPONSE);
return;
}
default: {
logger.write(MODULE_NAME, "[ERROR] run -> loop -> startUserBot -> onFinished -> Unhandled custom response received. -> err = " + err.message);
logger.persist();
@@ -760,18 +718,6 @@
case global.CUSTOM_OK_RESPONSE.result: {
switch (err.message) {
case "Too far in the future.": {
logger.write(MODULE_NAME, "[WARN] run -> loop -> intitializeProcessFramework -> onInizialized > Too far in the future. This Loop will enter in coma.");
nextWaitTime = 'Coma';
loopControl(nextWaitTime);
return;
}
case "Not needed now, but soon.": {
logger.write(MODULE_NAME, "[WARN] run -> loop -> intitializeProcessFramework -> onInizialized > Not needed now, but soon. This Loop will continue with Normal wait time.");
nextWaitTime = 'Normal';
loopControl(nextWaitTime);
return;
}
default: {
logger.write(MODULE_NAME, "[ERROR] run -> loop -> intitializeProcessFramework -> onInizialized > Unhandled custom response received. -> err = " + err.message);
logger.persist();
@@ -874,36 +820,6 @@
loopControl(nextWaitTime);
return;
}
case "Month before it is needed.": {
logger.write(MODULE_NAME, "[WARN] run -> loop -> startProcessFramework -> onFinished -> Month before it is needed. This Loop will be terminated.");
logger.persist();
clearInterval(fixedTimeLoopIntervalHandle);
clearTimeout(nextLoopTimeoutHandle);
clearTimeout(checkLoopHealthHandle);
bot.enableCheckLoopHealth = false;
callBackFunction(global.DEFAULT_OK_RESPONSE);
return;
}
case "Month fully processed.": {
logger.write(MODULE_NAME, "[WARN] run -> loop -> startProcessFramework -> onFinished -> Month fully processed. This Loop will be terminated.");
logger.persist();
clearInterval(fixedTimeLoopIntervalHandle);
clearTimeout(nextLoopTimeoutHandle);
clearTimeout(checkLoopHealthHandle);
bot.enableCheckLoopHealth = false;
callBackFunction(global.DEFAULT_OK_RESPONSE);
return;
}
case "End of the month reached.": {
logger.write(MODULE_NAME, "[WARN] run -> loop -> startProcessFramework -> onFinished -> End of the month reached. This Loop will be terminated.");
logger.persist();
clearInterval(fixedTimeLoopIntervalHandle);
clearTimeout(nextLoopTimeoutHandle);
clearTimeout(checkLoopHealthHandle);
bot.enableCheckLoopHealth = false;
callBackFunction(global.DEFAULT_OK_RESPONSE);
return;
}
default: {
logger.write(MODULE_NAME, "[ERROR] run -> loop -> startProcessFramework -> onFinished -> Unhandled custom response received. -> err = " + err.message);
logger.persist();
+9 -18
View File
@@ -19,25 +19,15 @@
let processThisDependsOn; // This is the process this process needs to wait for it to finishes in order to start.
let month;
let year;
let currentProcessKey
let datetimeForLogs = ''
return thisObject;
function initialize(pMonth, pYear, callBackFunction) {
function initialize(callBackFunction) {
try {
if (global.LOG_CONTROL[MODULE_NAME].logInfo === true) { logger.write(MODULE_NAME, "[INFO] initialize -> Entering function."); }
month = pMonth;
year = pYear;
if (month && year) {
datetimeForLogs = "Month: " + month + " Year: " + year
}
let name = 'Not Depends on any Process'
if (bot.processNode.referenceParent !== undefined) {
@@ -51,9 +41,9 @@
name = processThisDependsOn.name
if (processThisDependsOn.code.monthlyInstances === true) {
logger.fileName = MODULE_NAME + "." + name + "." + year + "." + month;
logger.fileName = MODULE_NAME + "." + name;
}
if (global.LOG_CONTROL[MODULE_NAME].logInfo === true) { logger.write(MODULE_NAME, "[INFO] initialize -> " + currentProcessKey + datetimeForLogs + " depends on " + name); }
if (global.LOG_CONTROL[MODULE_NAME].logInfo === true) { logger.write(MODULE_NAME, "[INFO] initialize -> " + currentProcessKey + " depends on " + name); }
}
}
}
@@ -79,8 +69,6 @@
/* This forces this process to wait until the process that this one depends on, emits its event signaling that the process execution has finished. */
let extraCallerId = '-' + Math.trunc(Math.random() * 10000) + '-'
if (month) { extraCallerId = extraCallerId + '-' + month }
if (year) { extraCallerId = extraCallerId + '-' + year }
let key = processThisDependsOn.name + "-" + processThisDependsOn.type + "-" + processThisDependsOn.id
let callerId = bot.dataMine + "-" + bot.codeName + "-" + bot.process + extraCallerId
@@ -92,6 +80,7 @@
if (global.LOG_CONTROL[MODULE_NAME].logInfo === true) { logger.write(MODULE_NAME, "[INFO] start -> waitForDependantProcess -> callerId = " + callerId); }
global.SYSTEM_EVENT_HANDLER.listenToEvent(key, 'Process Execution Finished', undefined, callerId, responseCallBack, eventsCallBack)
console.log("LISTENING TO EVENT:", 'Process Execution Finished', key)
function responseCallBack(message) {
if (message.result !== global.DEFAULT_OK_RESPONSE.result) {
@@ -120,7 +109,7 @@
global.SYSTEM_EVENT_HANDLER.createEventHandler(currentProcessKey, 'Process Execution Started')
global.SYSTEM_EVENT_HANDLER.raiseEvent(currentProcessKey, 'Process Execution Started', event)
if (global.LOG_CONTROL[MODULE_NAME].logInfo === true) { logger.write(MODULE_NAME, "[INFO] start -> eventsCallBack -> " + currentProcessKey + " Process Execution Started because " + key + datetimeForLogs + " Finished."); }
if (global.LOG_CONTROL[MODULE_NAME].logInfo === true) { logger.write(MODULE_NAME, "[INFO] start -> eventsCallBack -> " + currentProcessKey + " Process Execution Started because " + key + " Finished."); }
}
callBackFunction(message.event.err);
@@ -134,7 +123,7 @@
global.SYSTEM_EVENT_HANDLER.createEventHandler(currentProcessKey, 'Process Execution Started')
global.SYSTEM_EVENT_HANDLER.raiseEvent(currentProcessKey, 'Process Execution Started', event)
if (global.LOG_CONTROL[MODULE_NAME].logInfo === true) { logger.write(MODULE_NAME, "[INFO] start -> " + currentProcessKey + " Process Execution Started " + datetimeForLogs); }
if (global.LOG_CONTROL[MODULE_NAME].logInfo === true) { logger.write(MODULE_NAME, "[INFO] start -> " + currentProcessKey + " Process Execution Started " ); }
callBackFunction(global.DEFAULT_OK_RESPONSE);
}
@@ -157,7 +146,9 @@
global.SYSTEM_EVENT_HANDLER.createEventHandler(currentProcessKey, 'Process Execution Finished')
global.SYSTEM_EVENT_HANDLER.raiseEvent(currentProcessKey, 'Process Execution Finished', event)
if (global.LOG_CONTROL[MODULE_NAME].logInfo === true) { logger.write(MODULE_NAME, "[INFO] finish -> " + currentProcessKey + " Process Execution Finished " + datetimeForLogs); }
console.log("RAISING EVENT:", 'Process Execution Finished', currentProcessKey)
if (global.LOG_CONTROL[MODULE_NAME].logInfo === true) { logger.write(MODULE_NAME, "[INFO] finish -> " + currentProcessKey + " Process Execution Finished " ); }
callBackFunction(global.DEFAULT_OK_RESPONSE);
+10 -117
View File
@@ -281,97 +281,10 @@
try {
/* We test each type of start Mode to get what to run and how. */
if (processConfig.startMode.allMonths !== undefined) {
if (processConfig.startMode.allMonths.run === "true") {
if (FULL_LOG === true) { console.log(logDisplace + "Root : [INFO] start -> bootingBot -> allMonths start mode detected. "); }
for (let year = processConfig.startMode.allMonths.maxYear; year >= processConfig.startMode.allMonths.minYear; year--) {
for (let month = 12; month > 0; month--) {
let padMonth = pad(month, 2)
let newInstanceBotConfig = JSON.parse(JSON.stringify(botConfig));
newInstanceBotConfig.debug = {
month: pad(month, 2),
year: pad(year, 4)
};
let timeDelay = Math.random() * 10 * 1000; // We introduce a short delay so as to not overload the machine.
setTimeout(startProcess, timeDelay);
function startProcess() {
if (FULL_LOG === true) { console.log(logDisplace + "Root : [INFO] start -> bootingBot -> startProcess -> Ready to start process."); }
switch (botConfig.type) {
case 'Sensor Bot': {
runSensorBot(newInstanceBotConfig, processConfig, padMonth, year);
break;
}
case 'Indicator Bot': {
runIndicatorBot(newInstanceBotConfig, processConfig, padMonth, year);
break;
}
default: {
console.log(logDisplace + "Root : [ERROR] start -> bootingBot -> startProcess -> Unexpected bot type. -> botConfig.type = " + botConfig.type);
}
}
}
}
}
}
}
if (processConfig.startMode.oneMonth !== undefined) {
if (processConfig.startMode.oneMonth.run === "true") {
if (FULL_LOG === true) { console.log(logDisplace + "Root : [INFO] start -> bootingBot -> oneMonth start mode detected. "); }
startProcess();
function startProcess() {
if (FULL_LOG === true) { console.log(logDisplace + "Root : [INFO] start -> bootingBot -> startProcess -> Ready to start process."); }
let month = pad(processConfig.startMode.oneMonth.month, 2);
let year = processConfig.startMode.oneMonth.year;
botConfig.debug = {
month: pad(month, 2),
year: pad(year, 4)
};
switch (botConfig.type) {
case 'Sensor Bot': {
runSensorBot(botConfig, processConfig, month, year);
break;
}
case 'Indicator Bot': {
runIndicatorBot(botConfig, processConfig, month, year);
break;
}
default: {
console.log(logDisplace + "Root : [ERROR] start -> bootingBot -> startProcess -> Unexpected bot type. -> botConfig.type = " + botConfig.type);
}
}
}
}
}
if (processConfig.startMode.noTime !== undefined) {
if (processConfig.startMode.noTime.run === "true") {
let month = pad((new Date()).getUTCMonth() + 1, 2);
let year = (new Date()).getUTCFullYear();
if (processConfig.startMode.noTime.resumeExecution === true) {
botConfig.hasTheBotJustStarted = false;
} else {
@@ -380,11 +293,11 @@
switch (botConfig.type) {
case 'Sensor Bot': {
runSensorBot(botConfig, processConfig, month, year);
runSensorBot(botConfig, processConfig);
break;
}
case 'Indicator Bot': {
runIndicatorBot(botConfig, processConfig, month, year);
runIndicatorBot(botConfig, processConfig);
break;
}
case 'Trading Bot': {
@@ -405,12 +318,9 @@
botConfig.runAtFixedInterval = true;
botConfig.fixedInterval = processConfig.startMode.fixedInterval.interval;
let month = pad((new Date()).getUTCMonth() + 1, 2);
let year = (new Date()).getUTCFullYear();
switch (botConfig.type) {
case 'Sensor Bot': {
runSensorBot(botConfig, processConfig, month, year);
runSensorBot(botConfig, processConfig);
break;
}
default: {
@@ -427,9 +337,6 @@
botConfig.startMode = "User Defined";
console.log(logDisplace + "Root : [INFO] start -> bootingBot -> Process found at the bot configuration file. -> Start Mode = " + botConfig.startMode);
let month = pad((new Date()).getUTCMonth() + 1, 2);
let year = (new Date()).getUTCFullYear();
if (processConfig.startMode.userDefined.resumeExecution === true) {
botConfig.hasTheBotJustStarted = false;
} else {
@@ -453,7 +360,7 @@
}
function runSensorBot(pBotConfig, pProcessConfig, pMonth, pYear) {
function runSensorBot(pBotConfig, pProcessConfig) {
try {
global.TOTAL_PROCESS_INSTANCES_CREATED++
@@ -465,8 +372,6 @@
logger.bot = pBotConfig;
if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> bootingBot -> runSensorBot -> Entering function."); }
if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> bootingBot -> runSensorBot -> pMonth = " + pMonth); }
if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> bootingBot -> runSensorBot -> pYear = " + pYear); }
let extractionBotMainLoop = SENSOR_BOT_MAIN_LOOP_MODULE.newSensorBotProcessMainLoop(pBotConfig, logger);
extractionBotMainLoop.initialize(pProcessConfig, onInitializeReady);
@@ -475,18 +380,13 @@
if (err.result === global.DEFAULT_OK_RESPONSE.result) {
extractionBotMainLoop.run(pMonth, pYear, whenRunFinishes);
extractionBotMainLoop.run(whenRunFinishes);
function whenRunFinishes(err) {
pBotConfig.loopCounter = 0;
let botId;
if (pYear !== undefined) {
botId = pBotConfig.dataMine + "." + pBotConfig.codeName + "." + pBotConfig.process + "." + pYear + "." + pMonth;
} else {
botId = pBotConfig.dataMine + "." + pBotConfig.codeName + "." + pBotConfig.process;
}
let botId = pBotConfig.dataMine + "." + pBotConfig.codeName + "." + pBotConfig.process;
if (err.result === global.DEFAULT_OK_RESPONSE.result) {
@@ -527,7 +427,7 @@
}
}
function runIndicatorBot(pBotConfig, pProcessConfig, pMonth, pYear) {
function runIndicatorBot(pBotConfig, pProcessConfig) {
try {
global.TOTAL_PROCESS_INSTANCES_CREATED++
@@ -539,8 +439,6 @@
logger.bot = pBotConfig;
if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> bootingBot -> runIndicatorBot -> Entering function."); }
if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> bootingBot -> runIndicatorBot -> pMonth = " + pMonth); }
if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> bootingBot -> runIndicatorBot -> pYear = " + pYear); }
let indicatorBotMainLoop = INDICATOR_BOT_MAIN_LOOP_MODULE.newIndicatorBotProcessMainLoop(pBotConfig, logger);
indicatorBotMainLoop.initialize(pProcessConfig, onInitializeReady);
@@ -549,19 +447,14 @@
if (err.result === global.DEFAULT_OK_RESPONSE.result) {
indicatorBotMainLoop.run(pMonth, pYear, whenRunFinishes);
indicatorBotMainLoop.run(whenRunFinishes);
function whenRunFinishes(err) {
pBotConfig.loopCounter = 0;
let botId;
if (pYear !== undefined) {
botId = pBotConfig.dataMine + "." + pBotConfig.codeName + "." + pBotConfig.process + "." + pYear + "." + pMonth;
} else {
botId = pBotConfig.dataMine + "." + pBotConfig.codeName + "." + pBotConfig.process;
}
let botId = pBotConfig.dataMine + "." + pBotConfig.codeName + "." + pBotConfig.process;
if (err.result === global.DEFAULT_OK_RESPONSE.result) {
logger.write(MODULE_NAME, "[INFO] start -> bootingBot -> runIndicatorBot -> onInitializeReady -> whenStartFinishes -> Bot execution finished sucessfully.");
+5 -55
View File
@@ -92,7 +92,7 @@
}
}
function run(pMonth, pYear, callBackFunction) {
function run(callBackFunction) {
try {
if (FULL_LOG === true) { parentLogger.write(MODULE_NAME, "[INFO] run -> Entering function."); }
@@ -150,7 +150,7 @@
/* High level log entry */
console.log(new Date().toISOString() + " " + pad(bot.codeName, 20) + " " + pad(bot.process, 30) + " " + pad(pMonth, 2) + "/" + pad(pYear, 4)
console.log(new Date().toISOString() + " " + pad(bot.codeName, 20) + " " + pad(bot.process, 30) + " "
+ " Entered into Main Loop # " + pad(Number(bot.loopCounter), 8) + " bot.processDatetime = " + bot.processDatetime.toISOString());
/* We will prepare first the infraestructure needed for the bot to run. There are 4 modules we need to sucessfullly initialize first. */
@@ -173,7 +173,7 @@
processExecutionEvents = PROCESS_EXECUTION_EVENTS.newProcessExecutionEvents(bot, logger)
processExecutionEvents.initialize(pMonth, pYear, onInizialized);
processExecutionEvents.initialize(onInizialized);
function onInizialized(err) {
@@ -321,7 +321,7 @@
statusDependencies = STATUS_DEPENDENCIES.newStatusDependencies(bot, logger, STATUS_REPORT, UTILITIES);
statusDependencies.initialize(pMonth, pYear, onInizialized);
statusDependencies.initialize(onInizialized);
function onInizialized(err) {
@@ -396,7 +396,7 @@
usertBot = USER_BOT_MODULE.newUserBot(bot, logger, COMMONS_MODULE, UTILITIES, fileStorage, STATUS_REPORT, exchangeAPI);
usertBot.initialize(statusDependencies, pMonth, pYear, onInizialized);
usertBot.initialize(statusDependencies, onInizialized);
function onInizialized(err) {
@@ -430,26 +430,6 @@
case global.CUSTOM_OK_RESPONSE.result: {
switch (err.message) {
case "Too far in the future.": {
logger.write(MODULE_NAME, "[WARN] run -> loop -> initializeUserBot -> onInizialized > Too far in the future. This Loop will enter in coma.");
nextWaitTime = 'Coma';
clearInterval(fixedTimeLoopIntervalHandle);
clearTimeout(nextLoopTimeoutHandle);
clearTimeout(checkLoopHealthHandle);
bot.enableCheckLoopHealth = false;
loopControl(nextWaitTime);
return;
}
case "Not needed now, but soon.": {
logger.write(MODULE_NAME, "[WARN] run -> loop -> initializeUserBot -> onInizialized > Not needed now, but soon. This Loop will continue with Normal wait time.");
nextWaitTime = 'Normal';
clearInterval(fixedTimeLoopIntervalHandle);
clearTimeout(nextLoopTimeoutHandle);
clearTimeout(checkLoopHealthHandle);
bot.enableCheckLoopHealth = false;
loopControl(nextWaitTime);
return;
}
default: {
logger.write(MODULE_NAME, "[ERROR] run -> loop -> initializeUserBot -> onInizialized > Unhandled custom response received. -> err = " + err.message);
logger.persist();
@@ -550,36 +530,6 @@
loopControl(nextWaitTime);
return;
}
case "Month before it is needed.": {
logger.write(MODULE_NAME, "[WARN] run -> loop -> startUserBot -> onFinished > Month before it is needed. This Loop will be terminated.");
logger.persist();
clearInterval(fixedTimeLoopIntervalHandle);
clearTimeout(nextLoopTimeoutHandle);
clearTimeout(checkLoopHealthHandle);
bot.enableCheckLoopHealth = false;
callBackFunction(global.DEFAULT_OK_RESPONSE);
return;
}
case "Month fully processed.": {
logger.write(MODULE_NAME, "[WARN] run -> loop -> startUserBot -> onFinished > Month fully processed. This Loop will be terminated.");
logger.persist();
clearInterval(fixedTimeLoopIntervalHandle);
clearTimeout(nextLoopTimeoutHandle);
clearTimeout(checkLoopHealthHandle);
bot.enableCheckLoopHealth = false;
callBackFunction(global.DEFAULT_OK_RESPONSE);
return;
}
case "End of the month reached.": {
logger.write(MODULE_NAME, "[WARN] run -> loop -> startUserBot -> onFinished > End of the month reached. This Loop will be terminated.");
logger.persist();
clearInterval(fixedTimeLoopIntervalHandle);
clearTimeout(nextLoopTimeoutHandle);
clearTimeout(checkLoopHealthHandle);
bot.enableCheckLoopHealth = false;
callBackFunction(global.DEFAULT_OK_RESPONSE);
return;
}
default: {
logger.write(MODULE_NAME, "[ERROR] run -> loop -> startUserBot -> onFinished > Unhandled custom response received. -> err = " + err.message);
logger.persist();
+4 -26
View File
@@ -16,7 +16,7 @@
return thisObject;
function initialize(pMonth, pYear, callBackFunction) {
function initialize(callBackFunction) {
try {
@@ -44,27 +44,11 @@
let dependenciesToProcess = []
for (let i = 0; i < thisObject.nodeArray.length; i++) {
let statusDependency = {
dependency: thisObject.nodeArray[i],
month: pMonth,
year: pYear
dependency: thisObject.nodeArray[i]
}
dependenciesToProcess.push(statusDependency)
/*
For the special case that the statusDependency is a Self Reference AND this process is sliced in different
instances for each month, we will add the main self reference status report that is month/year independent.
*/
if (statusDependency.dependency.code.mainUtility === "Self Reference" && pMonth !== undefined && pYear !== undefined) {
let mainDependency = {
dependency: thisObject.nodeArray[i],
month: undefined,
year: undefined
}
dependenciesToProcess.push(mainDependency)
}
}
for (let i = 0; i < dependenciesToProcess.length; i++) {
@@ -73,7 +57,7 @@
logger.write(MODULE_NAME, "[INFO] initialize -> onInitilized -> Initializing Status Report # " + (i + 1));
let statusDependency = dependenciesToProcess[i]
statusReportModule.initialize(statusDependency.dependency, statusDependency.month, statusDependency.year, onInitilized);
statusReportModule.initialize(statusDependency.dependency, onInitilized);
function onInitilized(err) {
@@ -152,13 +136,7 @@
loadCount++;
logger.write(MODULE_NAME, "[INFO] initialize -> addReport -> Total Added = " + loadCount);
let key;
if (statusDependency.dependency.processRunMonthly === true && statusDependency.month !== undefined && statusDependency.year !== undefined) {
key = statusDependency.dependency.dataMine + "-" + statusDependency.dependency.bot + "-" + statusDependency.dependency.process + "-" + statusDependency.dependency.dataSetVersion + "-" + statusDependency.year + "-" + statusDependency.month;
} else {
key = statusDependency.dependency.dataMine + "-" + statusDependency.dependency.bot + "-" + statusDependency.dependency.process + "-" + statusDependency.dependency.dataSetVersion;
}
let key = statusDependency.dependency.dataMine + "-" + statusDependency.dependency.bot + "-" + statusDependency.dependency.process + "-" + statusDependency.dependency.dataSetVersion;
thisObject.keys.push(key);
thisObject.statusReports.set(key, statusReportModule);
+5 -266
View File
@@ -18,8 +18,7 @@
initialize: initialize,
load: load,
save: save,
status: undefined,
verifyMarketComplete: verifyMarketComplete
status: undefined
};
let statusDependencyNode;
@@ -33,14 +32,11 @@
const FILE_STORAGE = require('./FileStorage.js');
let fileStorage = FILE_STORAGE.newFileStorage(logger);
let month;
let year;
let timePath = '';
let sessionPath = ''
return thisObject;
function initialize(pStatusDependencyNode, pMonth, pYear, callBackFunction) {
function initialize(pStatusDependencyNode, callBackFunction) {
try {
if (global.LOG_CONTROL[MODULE_NAME].logInfo === true) { logger.write(MODULE_NAME, "[INFO] initialize -> Entering function."); }
@@ -48,9 +44,6 @@
statusDependencyNode = pStatusDependencyNode;
logger.fileName = MODULE_NAME + "." + statusDependencyNode.type + "." + statusDependencyNode.name + "." + statusDependencyNode.id;
month = pMonth;
year = pYear;
/* Some very basic validations that we have all the information needed. */
if (statusDependencyNode.referenceParent === undefined) {
logger.write(MODULE_NAME, "[ERROR] initialize -> Status Dependency without Reference Parent. Status Dependency = " + JSON.stringify(statusDependencyNode));
@@ -128,11 +121,6 @@
if (bot.SESSION !== undefined && statusDependencyNode.bottype === "Trading Bot") {
sessionPath = bot.SESSION.folderName + "/"
}
if (statusDependencyNode.processRunMonthly === true && month !== undefined && year !== undefined) {
logger.fileName = MODULE_NAME + "." + statusDependencyNode.bot + "." + statusDependencyNode.process + "." + year + "." + month;
timePath = "/" + year + "/" + month;
}
callBackFunction(global.DEFAULT_OK_RESPONSE);
@@ -156,9 +144,9 @@
if (ownerId !== botId) {
let rootPath = statusDependencyNode.dataMine + "/" + statusDependencyNode.bot + "/" + bot.exchange;
filePath = rootPath + "/Reports/" + sessionPath + statusDependencyNode.process + timePath;
filePath = rootPath + "/Reports/" + sessionPath + statusDependencyNode.process ;
} else {
filePath = bot.filePathRoot + "/Reports/" + sessionPath + statusDependencyNode.process + timePath;
filePath = bot.filePathRoot + "/Reports/" + sessionPath + statusDependencyNode.process ;
}
filePath += '/' + fileName
@@ -246,7 +234,7 @@
}
let fileName = "Status.Report." + bot.market.baseAsset + '_' + bot.market.quotedAsset + ".json";
let filePath = bot.filePathRoot + "/Reports/" + sessionPath + statusDependencyNode.process + timePath;
let filePath = bot.filePathRoot + "/Reports/" + sessionPath + statusDependencyNode.process;
filePath += '/' + fileName
let fileContent = JSON.stringify(thisObject.file);
@@ -278,253 +266,4 @@
}
}
function verifyMarketComplete(callBackFunction) {
/*
The mission of this function is to update the main status report on a scheme where there are monthly sub reports.
This report contains the date of the last file sucessfully checked but in a consecutive way.
For example: if the market starts in March, and March, April and June are checked, then the file will be the last of June even if September is also checked.
IMPORTANT NOTE: Once executed, this function will leave thisObject in an inconsistant state, so you need to re-initialize it if you wish to use it again.
*/
try {
if (global.LOG_CONTROL[MODULE_NAME].logInfo === true) { logger.write(MODULE_NAME, "[INFO] verifyMarketComplete -> Entering function."); }
let initialYear;
let initialMonth;
let finalYear = (new Date()).getUTCFullYear();
let finalMonth = (new Date()).getUTCMonth() + 1;
/* Lets load again this main status report as it might have changed since its initialization and first load. */
load(onLoad);
function onLoad(err) {
try {
if (global.LOG_CONTROL[MODULE_NAME].logInfo === true) { logger.write(MODULE_NAME, "[INFO] verifyMarketComplete -> onLoad -> Entering function."); }
if (
err.result === global.CUSTOM_FAIL_RESPONSE.result &&
(err.message === 'Status Report was never created.')
) {
logger.write(MODULE_NAME, "[INFO] verifyMarketComplete -> onLoad -> err = "+ err.stack);
/* The first month of the market didnt create the main report yet. Aborting verification. */
if (global.LOG_CONTROL[MODULE_NAME].logInfo === true) { logger.write(MODULE_NAME, "[INFO] verifyMarketComplete -> onLoad -> Verification ABORTED since the main status report does not exist."); }
callBackFunction(global.DEFAULT_OK_RESPONSE);
return;
}
if (err.result !== global.DEFAULT_OK_RESPONSE.result) {
logger.write(MODULE_NAME, "[ERROR] verifyMarketComplete -> onLoad -> err = "+ err.stack);
callBackFunction(err);
return;
}
/* Here we get the initial month and year from where our verification process will start. */
initialYear = thisObject.file.lastFile.year;
initialMonth = thisObject.file.lastFile.month;
loopCycle();
} catch (err) {
logger.write(MODULE_NAME, "[ERROR] verifyMarketComplete -> onLoad -> err = "+ err.stack);
callBackFunction(global.DEFAULT_FAIL_RESPONSE);
return;
}
}
function loopCycle() {
try {
if (global.LOG_CONTROL[MODULE_NAME].logInfo === true) { logger.write(MODULE_NAME, "[INFO] verifyMarketComplete -> loopCycle -> Entering function."); }
/* Here we read the status report file of each month / year to verify if it is complete or not. */
let paddedInitialMonth = utilities.pad(initialMonth, 2);
timePath = "/" + initialYear + "/" + paddedInitialMonth;
load(onLoad);
function onLoad(err) {
try {
if (global.LOG_CONTROL[MODULE_NAME].logInfo === true) { logger.write(MODULE_NAME, "[INFO] verifyMarketComplete -> loopCycle -> onLoad -> Entering function."); }
if (
err.result === global.CUSTOM_FAIL_RESPONSE.result &&
(err.message === 'Status Report was never created.')
) {
logger.write(MODULE_NAME, "[INFO] verifyMarketComplete -> loopCycle -> onLoad -> err = "+ err.stack);
/* The first month of the market didnt create the main report yet. Aborting verification. */
if (global.LOG_CONTROL[MODULE_NAME].logInfo === true) { logger.write(MODULE_NAME, "[INFO] verifyMarketComplete -> loopCycle -> onLoad -> Verification ABORTED since the status report for year " + initialYear + " and month " + initialMonth + " did not exist. "); }
callBackFunction(global.DEFAULT_OK_RESPONSE);
return;
}
if (err.result !== global.DEFAULT_OK_RESPONSE.result) {
logger.write(MODULE_NAME, "[ERROR] verifyMarketComplete -> loopCycle -> onLoad -> err = "+ err.stack);
callBackFunction(err);
return;
}
if (thisObject.file.monthChecked === true) {
readAndWriteNewReport(JSON.stringify(thisObject.file));
} else {
/* If any of the files says that month is not checked then it is enough to know the market continuity is broken. */
if (global.LOG_CONTROL[MODULE_NAME].logInfo === true) { logger.write(MODULE_NAME, "[INFO] verifyMarketComplete -> loopCycle -> onLoad -> Verification ABORTED since the status report for year " + initialYear + " and month " + initialMonth + " is not marked as complete."); }
callBackFunction(global.DEFAULT_OK_RESPONSE);
return;
}
} catch (err) {
logger.write(MODULE_NAME, "[ERROR] verifyMarketComplete -> loopCycle -> onLoad -> err = "+ err.stack);
callBackFunction(global.DEFAULT_FAIL_RESPONSE);
return;
}
}
} catch (err) {
logger.write(MODULE_NAME, "[ERROR] verifyMarketComplete -> loopCycle -> err = "+ err.stack);
callBackFunction(global.DEFAULT_FAIL_RESPONSE);
return;
}
}
function readAndWriteNewReport(monthlyStatusReport) {
try {
if (global.LOG_CONTROL[MODULE_NAME].logInfo === true) { logger.write(MODULE_NAME, "[INFO] verifyMarketComplete -> readAndWriteNewReport -> Entering function."); }
/* We will read the current file to preserve its data, and save it again with the new lastFile */
monthlyStatusReport = JSON.parse(monthlyStatusReport);
timePath = "";
load(onLoad);
function onLoad(err) {
try {
if (global.LOG_CONTROL[MODULE_NAME].logInfo === true) { logger.write(MODULE_NAME, "[INFO] verifyMarketComplete -> readAndWriteNewReport -> onLoad -> Entering function."); }
if (err.result !== global.DEFAULT_OK_RESPONSE.result) {
logger.write(MODULE_NAME, "[ERROR] verifyMarketComplete -> readAndWriteNewReport -> onLoad -> err = "+ err.stack);
callBackFunction(err);
return;
}
if (monthlyStatusReport.lastTrade.id > thisObject.file.lastTrade.id) {
thisObject.file.lastFile = monthlyStatusReport.lastFile;
thisObject.file.lastTrade = monthlyStatusReport.lastTrade;
thisObject.file.lastTrade.counter = undefined;
save(onSave);
function onSave(err) {
try {
if (global.LOG_CONTROL[MODULE_NAME].logInfo === true) { logger.write(MODULE_NAME, "[INFO] verifyMarketComplete -> readAndWriteNewReport -> onLoad -> onSave -> Entering function."); }
if (err.result !== global.DEFAULT_OK_RESPONSE.result) {
logger.write(MODULE_NAME, "[ERROR] verifyMarketComplete -> readAndWriteNewReport -> onLoad -> onSave -> err = "+ err.stack);
callBackFunction(err);
return;
}
loop(); // Lets see the next month.
} catch (err) {
logger.write(MODULE_NAME, "[ERROR] verifyMarketComplete -> readAndWriteNewReport -> onLoad -> onSave -> err = "+ err.stack);
callBackFunction(global.DEFAULT_FAIL_RESPONSE);
return;
}
}
} else {
if (global.LOG_CONTROL[MODULE_NAME].logInfo === true) { logger.write(MODULE_NAME, "[INFO] verifyMarketComplete -> readAndWriteNewReport -> onLoad -> Main Status Report Not Updated."); }
if (global.LOG_CONTROL[MODULE_NAME].logInfo === true) { logger.write(MODULE_NAME, "[INFO] verifyMarketComplete -> readAndWriteNewReport -> onLoad -> Current Trade Id (" + monthlyStatusReport.lastTrade.id + ") is <= than Id at main status report file. (" + thisObject.file.lastTrade.id + ")"); }
loop(); // Lets see the next month.
}
} catch (err) {
logger.write(MODULE_NAME, "[ERROR] verifyMarketComplete -> readAndWriteNewReport -> onLoad -> err = "+ err.stack);
callBackFunction(global.DEFAULT_FAIL_RESPONSE);
return;
}
}
} catch (err) {
logger.write(MODULE_NAME, "[ERROR] verifyMarketComplete -> loopCycle -> err = "+ err.stack);
callBackFunction(global.DEFAULT_FAIL_RESPONSE);
return;
}
}
function loop() {
try {
if (global.LOG_CONTROL[MODULE_NAME].logInfo === true) { logger.write(MODULE_NAME, "[INFO] verifyMarketComplete -> loop -> Entering function."); }
initialMonth++;
if (initialMonth > 12) {
initialMonth = 1;
initialYear++;
}
if ((initialYear === finalYear && initialMonth > finalMonth) || (initialYear > finalYear)) {
/* We arrived to the point where we have checked all the status reports of every month and they are all complete. */
if (global.LOG_CONTROL[MODULE_NAME].logInfo === true) { logger.write(MODULE_NAME, "[INFO] verifyMarketComplete -> loop -> Verification Finished. Success."); }
callBackFunction(global.DEFAULT_OK_RESPONSE);
return;
}
loopCycle();
} catch (err) {
logger.write(MODULE_NAME, "[ERROR] verifyMarketComplete -> loop -> err = "+ err.stack);
callBackFunction(global.DEFAULT_FAIL_RESPONSE);
return;
}
}
}
catch (err) {
logger.write(MODULE_NAME, "[ERROR] verifyMarketComplete -> err = "+ err.stack);
callBackFunction(global.DEFAULT_FAIL_RESPONSE);
return;
}
}
};
-42
View File
@@ -791,18 +791,6 @@
case global.CUSTOM_OK_RESPONSE.result: {
switch (err.message) {
case "Too far in the future.": {
logger.write(MODULE_NAME, "[WARN] run -> loop -> intitializeProcessFramework -> onInizialized > Too far in the future. This Loop will enter in coma.");
nextWaitTime = 'Coma';
loopControl(nextWaitTime);
return;
}
case "Not needed now, but soon.": {
logger.write(MODULE_NAME, "[WARN] run -> loop -> intitializeProcessFramework -> onInizialized > Not needed now, but soon. This Loop will continue with Normal wait time.");
nextWaitTime = 'Normal';
loopControl(nextWaitTime);
return;
}
default: {
logger.write(MODULE_NAME, "[ERROR] run -> loop -> intitializeProcessFramework -> onInizialized > Unhandled custom response received. -> err = " + err.message);
logger.persist();
@@ -907,36 +895,6 @@
loopControl(nextWaitTime);
return;
}
case "Month before it is needed.": {
logger.write(MODULE_NAME, "[WARN] run -> loop -> startProcessFramework -> onFinished -> Month before it is needed. This Loop will be terminated.");
logger.persist();
clearInterval(fixedTimeLoopIntervalHandle);
clearTimeout(nextLoopTimeoutHandle);
clearTimeout(checkLoopHealthHandle);
bot.enableCheckLoopHealth = false;
callBackFunction(global.DEFAULT_OK_RESPONSE);
return;
}
case "Month fully processed.": {
logger.write(MODULE_NAME, "[WARN] run -> loop -> startProcessFramework -> onFinished -> Month fully processed. This Loop will be terminated.");
logger.persist();
clearInterval(fixedTimeLoopIntervalHandle);
clearTimeout(nextLoopTimeoutHandle);
clearTimeout(checkLoopHealthHandle);
bot.enableCheckLoopHealth = false;
callBackFunction(global.DEFAULT_OK_RESPONSE);
return;
}
case "End of the month reached.": {
logger.write(MODULE_NAME, "[WARN] run -> loop -> startProcessFramework -> onFinished -> End of the month reached. This Loop will be terminated.");
logger.persist();
clearInterval(fixedTimeLoopIntervalHandle);
clearTimeout(nextLoopTimeoutHandle);
clearTimeout(checkLoopHealthHandle);
bot.enableCheckLoopHealth = false;
callBackFunction(global.DEFAULT_OK_RESPONSE);
return;
}
default: {
logger.write(MODULE_NAME, "[ERROR] run -> loop -> startProcessFramework -> onFinished -> Unhandled custom response received. -> err = " + err.message);
logger.persist();