From 6130b2473a15829e8d138b52d760cfda5285cfca Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Tue, 17 Sep 2019 16:04:04 +0200 Subject: [PATCH 01/13] Bug Fixes and Improvements to better respond to UI --- CloneExecutor.sln | 25 ------------------------- MultiPeriod.js | 32 ++++++++++++++++++++++++++------ TradingEngineProcessMainLoop.js | 5 +++++ 3 files changed, 31 insertions(+), 31 deletions(-) delete mode 100644 CloneExecutor.sln diff --git a/CloneExecutor.sln b/CloneExecutor.sln deleted file mode 100644 index a21837e88..000000000 --- a/CloneExecutor.sln +++ /dev/null @@ -1,25 +0,0 @@ - -Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio 15 -VisualStudioVersion = 15.0.27130.2027 -MinimumVisualStudioVersion = 10.0.40219.1 -Project("{9092AA53-FB77-4645-B42D-1CCCA6BD08BD}") = "Project", "Project.njsproj", "{AE0A3FE2-7021-4CC2-9922-A887CA5CDD7C}" -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|Any CPU = Debug|Any CPU - Release|Any CPU = Release|Any CPU - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {AE0A3FE2-7021-4CC2-9922-A887CA5CDD7C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {AE0A3FE2-7021-4CC2-9922-A887CA5CDD7C}.Debug|Any CPU.Build.0 = Debug|Any CPU - {AE0A3FE2-7021-4CC2-9922-A887CA5CDD7C}.Release|Any CPU.ActiveCfg = Release|Any CPU - {AE0A3FE2-7021-4CC2-9922-A887CA5CDD7C}.Release|Any CPU.Build.0 = Release|Any CPU - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection - GlobalSection(ExtensibilityGlobals) = postSolution - SolutionGuid = {9128DF06-8CA5-497C-8BF7-B924571C5394} - EndGlobalSection -EndGlobal diff --git a/MultiPeriod.js b/MultiPeriod.js index c1faa087f..58700cb52 100644 --- a/MultiPeriod.js +++ b/MultiPeriod.js @@ -115,6 +115,8 @@ /* We look first for the bot who knows the begining of the marke in order to get when the market starts. + IMPORTANT NOTE: When this module is used by Trading Engine Bots it nevers comes through this path since there is allways a ficed start date. + This code would be used by some indicator that is. */ let botWhoKnowsTheBeginingOfTheMarket = statusDependencies.config[processConfig.framework.startDate.takeItFromStatusDependency]; @@ -151,7 +153,7 @@ return; } - contextVariables.dateBeginOfMarket = new Date(thisReport.lastFile.year + "-" + thisReport.lastFile.month + "-" + thisReport.lastFile.days + " " + thisReport.lastFile.hours + ":" + thisReport.lastFile.minutes + GMT_SECONDS); + contextVariables.dateBeginOfMarket = new Date(thisReport.lastFile); } @@ -878,7 +880,8 @@ botNeverRan = false; if (currentTimePeriod > global.dailyFilePeriods[0][0]) { - writeMarketStatusReport(onMarketStatusReport); + writeMarketStatusReport(onMarketStatusReport) + } else { writeDataRanges(onWritten); } @@ -895,7 +898,7 @@ return; } - writeDailyStatusReport(bot.multiPeriodDailyProcessDatetime, advanceTime); + writeDailyStatusReport(bot.multiPeriodDailyProcessDatetime, onDailyStatusReport); } catch (err) { logger.write(MODULE_NAME, "[ERROR] start -> processTimePeriodsDailyFiles -> callTheBot -> onBotFinished -> onWritten -> err = " + err.stack); @@ -903,9 +906,29 @@ } } + + function onDailyStatusReport() { + try { + if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> processTimePeriodsDailyFiles -> callTheBot -> onBotFinished -> onDailyStatusReport -> Entering function."); } + + /* The next run we need the process to continue at the date it finished. */ + processConfig.framework.startDate.resumeExecution = true; + + advanceTime(); + } catch (err) { + logger.write(MODULE_NAME, "[ERROR] start -> processTimePeriodsDailyFiles -> callTheBot -> onBotFinished -> onDailyStatusReport -> err = " + err.stack); + callBackFunction(global.DEFAULT_FAIL_RESPONSE); + } + } + function onMarketStatusReport() { try { if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> processTimePeriodsDailyFiles -> callTheBot -> onBotFinished -> onMarketStatusReport -> Entering function."); } + + if (bot.startMode === "Backtest") { + global.STOP_PROCESSING = true + } + callBackFunction(global.DEFAULT_OK_RESPONSE); } catch (err) { logger.write(MODULE_NAME, "[ERROR] start -> processTimePeriodsDailyFiles -> callTheBot -> onBotFinished -> onMarketStatusReport -> err = " + err.stack); @@ -1023,9 +1046,6 @@ bot.hasTheBotJustStarted = false; - /* Emit event that signals that this process finished */ - global.SYSTEM_EVENT_HANDLER.raiseEvent('Jason-Multi-Period', 'Status Report Updated', { lastProcessedDay: lastFileDate }) - } catch (err) { logger.write(MODULE_NAME, "[ERROR] start -> writeDailyStatusReport -> err = " + err.stack); diff --git a/TradingEngineProcessMainLoop.js b/TradingEngineProcessMainLoop.js index 69fc465e5..e2748d820 100644 --- a/TradingEngineProcessMainLoop.js +++ b/TradingEngineProcessMainLoop.js @@ -183,6 +183,7 @@ let nextWaitTime; /* Loop Heartbeat sent to the UI */ + bot.hearBeat = hearBeat // allow the bot itself to produce a heartbeat hearBeat() /* We define here all the modules that the rest of the infraestructure, including the bots themselves can consume. */ @@ -209,6 +210,9 @@ if (global.STOP_PROCESSING === true) { if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] run -> loop -> We are going to skip this Loop bacause we were requested to stop or never asked to start."); } console.log("[INFO] run -> loop -> We are going to skip this Loop bacause we were requested to stop or never asked to start.") + + global.SYSTEM_EVENT_HANDLER.raiseEvent('Jason-Multi-Period', 'Process Stopped') + nextWaitTime = 'Normal'; loopControl(nextWaitTime); return @@ -1072,6 +1076,7 @@ } global.SYSTEM_EVENT_HANDLER.raiseEvent(key, 'Heartbeat', event) } + } catch (err) { parentLogger.write(MODULE_NAME, "[ERROR] run -> err = "+ err.stack); clearInterval(fixedTimeLoopIntervalHandle); From 26f53b0ab9187255b33eb77f05d95bc9ed4143b8 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Tue, 17 Sep 2019 19:29:00 +0200 Subject: [PATCH 02/13] Memory Leak Bug Fixed --- IndicatorBotProcessMainLoop.js | 2 ++ MultiPeriod.js | 16 +++++++++++++++- MultiPeriodDaily.js | 12 ++++++++++++ MultiPeriodMarket.js | 12 ++++++++++++ TradingEngineProcessMainLoop.js | 4 ++++ 5 files changed, 45 insertions(+), 1 deletion(-) diff --git a/IndicatorBotProcessMainLoop.js b/IndicatorBotProcessMainLoop.js index a1bfe1ef8..a152d2ed2 100644 --- a/IndicatorBotProcessMainLoop.js +++ b/IndicatorBotProcessMainLoop.js @@ -672,6 +672,8 @@ try { if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] run -> loop -> startProcessFramework -> onFinished -> Entering function."); } + processFramework.finalize() + processFramework = undefined switch (err.result) { case global.DEFAULT_OK_RESPONSE.result: { diff --git a/MultiPeriod.js b/MultiPeriod.js index 58700cb52..4d1c8b81f 100644 --- a/MultiPeriod.js +++ b/MultiPeriod.js @@ -8,6 +8,7 @@ thisObject = { initialize: initialize, + finalize: finalize, start: start }; @@ -68,6 +69,19 @@ } } + function finalize() { + storages = undefined + dataFiles = undefined + multiPeriodDataFiles = undefined + statusDependencies = undefined + dataDependencies = undefined + usertBot.finalize() + usertBot = undefined + fileStorage = undefined + processConfig = undefined + thisObject = undefined + } + function start(callBackFunction) { try { @@ -855,7 +869,7 @@ try { if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> processTimePeriodsDailyFiles -> callTheBot -> Entering function."); } - + usertBot.start( multiPeriodDataFiles, currentTimePeriod, diff --git a/MultiPeriodDaily.js b/MultiPeriodDaily.js index b3ce60d62..8a7ce9d1b 100644 --- a/MultiPeriodDaily.js +++ b/MultiPeriodDaily.js @@ -8,6 +8,7 @@ thisObject = { initialize: initialize, + finalize: finalize, start: start }; @@ -67,6 +68,17 @@ } } + function finalize() { + storages = undefined + dataFiles = undefined + statusDependencies = undefined + dataDependencies = undefined + usertBot = undefined + fileStorage = undefined + processConfig = undefined + thisObject = undefined + } + function start(callBackFunction) { try { diff --git a/MultiPeriodMarket.js b/MultiPeriodMarket.js index c03f1420a..d3dfe3ac1 100644 --- a/MultiPeriodMarket.js +++ b/MultiPeriodMarket.js @@ -6,6 +6,7 @@ thisObject = { initialize: initialize, + finalize: finalize, start: start }; @@ -65,6 +66,17 @@ } } + function finalize() { + storages = undefined + dataFiles = undefined + statusDependencies = undefined + dataDependencies = undefined + usertBot = undefined + fileStorage = undefined + processConfig = undefined + thisObject = undefined + } + function start(callBackFunction) { try { diff --git a/TradingEngineProcessMainLoop.js b/TradingEngineProcessMainLoop.js index e2748d820..bb951436f 100644 --- a/TradingEngineProcessMainLoop.js +++ b/TradingEngineProcessMainLoop.js @@ -140,6 +140,7 @@ } } } + bot.multiPeriodDailyProcessDatetime = processConfig.framework.startDate.fixedDate } function startLiveTrading(message) { @@ -150,6 +151,7 @@ bot.startMode = "Live" processConfig.framework.startDate.fixedDate = new Date() processConfig.framework.startDate.resumeExecution = false; + bot.multiPeriodDailyProcessDatetime = processConfig.framework.startDate.fixedDate global.STOP_PROCESSING = false bot.hasTheBotJustStarted = true } @@ -742,6 +744,8 @@ try { if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] run -> loop -> startProcessFramework -> onFinished -> Entering function."); } + processFramework.finalize() + processFramework = undefined switch (err.result) { case global.DEFAULT_OK_RESPONSE.result: { From 8c93a49021fbee1881193f12edc6d58ef63eeba4 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Tue, 17 Sep 2019 20:15:51 +0200 Subject: [PATCH 03/13] Stabilization Day Finished --- SystemEventHandler.js | 3 ++- TradingEngineProcessMainLoop.js | 2 ++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/SystemEventHandler.js b/SystemEventHandler.js index 7620ca72e..f86270062 100644 --- a/SystemEventHandler.js +++ b/SystemEventHandler.js @@ -48,10 +48,11 @@ 'message', // here is where all incomming messages are processed. function (data) { ipc.log('Got a message from Superalgos Event Server: '.debug, data); - + let message = JSON.parse(data) if (message.action === 'Event Raised') { + let key if (message.callerId) { key = message.eventHandlerName + '-' + message.eventType + '-' + message.callerId diff --git a/TradingEngineProcessMainLoop.js b/TradingEngineProcessMainLoop.js index bb951436f..3eadcadf0 100644 --- a/TradingEngineProcessMainLoop.js +++ b/TradingEngineProcessMainLoop.js @@ -963,6 +963,8 @@ logger.persist(); } + global.SYSTEM_EVENT_HANDLER.raiseEvent('Jason-Multi-Period', 'Process Stopped') + callBackFunction(global.DEFAULT_OK_RESPONSE); return; From 328e4f4bf7c132dd90247e56aed2edebab7968b6 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Wed, 18 Sep 2019 12:05:03 +0200 Subject: [PATCH 04/13] Massive cleaning and Tyding Up --- Context.js | 10 ++--- DebugLog.js | 2 +- IndicatorBotProcessMainLoop.js | 10 ++--- MultiPeriod.js | 2 +- MultiPeriodDaily.js | 2 +- Root.js | 12 +++--- SensorBotProcessMainLoop.js | 10 ++--- TradingEngineProcessMainLoop.js | 10 ++--- server.js | 73 ++++++++++++++++++++------------- 9 files changed, 74 insertions(+), 57 deletions(-) diff --git a/Context.js b/Context.js index dfa757cba..c3e7a9b6a 100644 --- a/Context.js +++ b/Context.js @@ -165,7 +165,7 @@ let fileName = "Execution.History." + bot.startMode + "." + runIndex + ".json"; let filePath = bot.filePathRoot + "/Output/Trading-Process/" + fileName; - fileStorage.getTextFile(global.DEV_TEAM, filePath, onFileReceived); + fileStorage.getTextFile(bot.devTeam, filePath, onFileReceived); function onFileReceived(err, text) { @@ -226,7 +226,7 @@ let dateForPath = date.getUTCFullYear() + '/' + utilities.pad(date.getUTCMonth() + 1, 2) + '/' + utilities.pad(date.getUTCDate(), 2) + '/' + utilities.pad(date.getUTCHours(), 2) + '/' + utilities.pad(date.getUTCMinutes(), 2); let filePath = bot.filePathRoot + "/Output/Trading-Process/" + dateForPath + fileName; - fileStorage.getTextFile(global.DEV_TEAM, filePath, onFileReceived); + fileStorage.getTextFile(bot.devTeam, filePath, onFileReceived); function onFileReceived(err, text) { @@ -408,7 +408,7 @@ if (global.LOG_CONTROL[MODULE_NAME].logContent === true) { logger.write(MODULE_NAME, "[INFO] saveThemAll -> writeExecutionContext -> fileContent = " + fileContent); } - fileStorage.createTextFile(global.DEV_TEAM, filePath, fileContent + '\n', onFileCreated); + fileStorage.createTextFile(bot.devTeam, filePath, fileContent + '\n', onFileCreated); function onFileCreated(err) { @@ -469,7 +469,7 @@ let fileContent = JSON.stringify(thisObject.executionHistory); - fileStorage.createTextFile(global.DEV_TEAM, filePath, fileContent + '\n', onFileCreated); + fileStorage.createTextFile(bot.devTeam, filePath, fileContent + '\n', onFileCreated); function onFileCreated(err) { @@ -491,7 +491,7 @@ fileName = "Execution.History." + bot.startMode + "." + "Sequence" + ".json"; filePath = bot.filePathRoot + "/Output/Trading-Process/" + fileName; - fileStorage.createTextFile(global.DEV_TEAM, filePath, fileContent + '\n', onSequenceFileCreated); + fileStorage.createTextFile(bot.devTeam, filePath, fileContent + '\n', onSequenceFileCreated); function onSequenceFileCreated(err) { diff --git a/DebugLog.js b/DebugLog.js index 5112b0882..baa9fc203 100644 --- a/DebugLog.js +++ b/DebugLog.js @@ -89,7 +89,7 @@ exports.newDebugLog = function newDebugLog() { function writeLog() { - fileStorage.createTextFile(global.DEV_TEAM, filePath + '/' + fileName, contentToPersist + '\r\n' + "]", onFileCreated); + fileStorage.createTextFile(thisObject.bot.devTeam, filePath + '/' + fileName, contentToPersist + '\r\n' + "]", onFileCreated); function onFileCreated(err) { diff --git a/IndicatorBotProcessMainLoop.js b/IndicatorBotProcessMainLoop.js index a152d2ed2..abc233a36 100644 --- a/IndicatorBotProcessMainLoop.js +++ b/IndicatorBotProcessMainLoop.js @@ -39,10 +39,10 @@ UI_COMMANDS = pUI_COMMANDS; processConfig = pProcessConfig; - let filePath = global.DEV_TEAM + "/" + "bots" + "/" + bot.repo + "/" + pProcessConfig.name + let filePath = bot.devTeam + "/" + "bots" + "/" + bot.repo + "/" + pProcessConfig.name filePath += "/User.Bot.js" - fileStorage.getTextFile(global.DEV_TEAM, filePath, onBotDownloaded); + fileStorage.getTextFile(bot.devTeam, filePath, onBotDownloaded); function onBotDownloaded(err, text) { @@ -56,10 +56,10 @@ USER_BOT_MODULE = {} USER_BOT_MODULE.newUserBot = eval(text); // TODO This needs to be changed function - filePath = global.DEV_TEAM + "/" + "bots" + "/" + bot.repo; + filePath = bot.devTeam + "/" + "bots" + "/" + bot.repo; filePath += "/Commons.js" - fileStorage.getTextFile(global.DEV_TEAM, filePath, onCommonsDownloaded); + fileStorage.getTextFile(bot.devTeam, filePath, onCommonsDownloaded); function onCommonsDownloaded(err, text) { @@ -923,7 +923,7 @@ } function hearBeat() { - let key = global.USER_DEFINITION.bot.processes[bot.processIndex].name + '-' + global.USER_DEFINITION.bot.processes[bot.processIndex].type + '-' + global.USER_DEFINITION.bot.processes[bot.processIndex].id + let key = global.TASK_NODE.bot.processes[bot.processIndex].name + '-' + global.TASK_NODE.bot.processes[bot.processIndex].type + '-' + global.TASK_NODE.bot.processes[bot.processIndex].id let event = { seconds: (new Date()).getSeconds() diff --git a/MultiPeriod.js b/MultiPeriod.js index 4d1c8b81f..646254c90 100644 --- a/MultiPeriod.js +++ b/MultiPeriod.js @@ -1018,7 +1018,7 @@ let fileName = '/Data.Range.' + market.assetA + '_' + market.assetB + '.json'; let filePath = bot.filePathRoot + "/Output/" + pProductFolder + "/" + 'Multi-Period-Daily' + fileName; - fileStorage.createTextFile(global.DEV_TEAM, filePath, fileContent + '\n', onFileCreated); + fileStorage.createTextFile(bot.devTeam, filePath, fileContent + '\n', onFileCreated); function onFileCreated(err) { diff --git a/MultiPeriodDaily.js b/MultiPeriodDaily.js index 8a7ce9d1b..7544c5404 100644 --- a/MultiPeriodDaily.js +++ b/MultiPeriodDaily.js @@ -722,7 +722,7 @@ let fileName = '/Data.Range.' + market.assetA + '_' + market.assetB + '.json'; let filePath = bot.filePathRoot + "/Output/" + pProductFolder + "/" + bot.process + fileName; - fileStorage.createTextFile(global.DEV_TEAM, filePath, fileContent + '\n', onFileCreated); + fileStorage.createTextFile(bot.devTeam, filePath, fileContent + '\n', onFileCreated); function onFileCreated(err) { diff --git a/Root.js b/Root.js index b26b69501..b160dbba1 100644 --- a/Root.js +++ b/Root.js @@ -143,9 +143,9 @@ const FILE_STORAGE = require('./Integrations/FileStorage.js'); let fileStorage = FILE_STORAGE.newFileStorage(); - let filePath = global.DEV_TEAM + '/bots/' + global.CURRENT_BOT_REPO + '/this.bot.config.json'; + let filePath = global.TASK_NODE.bot.processes[processIndex].code.team + '/bots/' + global.TASK_NODE.bot.processes[processIndex].code.repo + '/this.bot.config.json'; - fileStorage.getTextFile(global.DEV_TEAM, filePath, onFileReceived); + fileStorage.getTextFile(global.TASK_NODE.bot.processes[processIndex].code.team, filePath, onFileReceived); function onFileReceived(err, text) { @@ -338,7 +338,7 @@ runIndicatorBot(botConfig, processConfig, month, year); break; } - case 'Trading-Engine': { + case 'Trading Engine': { runTradingEngine(botConfig, processConfig); break; } @@ -388,7 +388,7 @@ } switch (botConfig.type) { - case 'Trading-Engine': { + case 'Trading Engine': { runTradingEngine(botConfig, processConfig); break; } @@ -632,14 +632,14 @@ function exitProcessInstance() { global.ENDED_PROCESSES_COUNTER++ - console.log("[INFO] Task Server -> " + global.USER_DEFINITION.name + " -> exitProcessInstance -> Process #" + global.ENDED_PROCESSES_COUNTER + " from " + global.TOTAL_PROCESS_INSTANCES_CREATED + " exiting."); + console.log("[INFO] Task Server -> " + global.TASK_NODE.name + " -> exitProcessInstance -> Process #" + global.ENDED_PROCESSES_COUNTER + " from " + global.TOTAL_PROCESS_INSTANCES_CREATED + " exiting."); if (global.ENDED_PROCESSES_COUNTER === global.TOTAL_PROCESS_INSTANCES_CREATED) { global.EXIT_NODE_PROCESS() } } } catch (err) { - console.log("[ERROR] Task Server -> " + global.USER_DEFINITION.name + " -> Root -> Start -> Err = " + err.stack); + console.log("[ERROR] Task Server -> " + global.TASK_NODE.name + " -> Root -> Start -> Err = " + err.stack); } } } diff --git a/SensorBotProcessMainLoop.js b/SensorBotProcessMainLoop.js index dda3a4a8f..b3307aba0 100644 --- a/SensorBotProcessMainLoop.js +++ b/SensorBotProcessMainLoop.js @@ -37,10 +37,10 @@ UI_COMMANDS = pUI_COMMANDS; processConfig = pProcessConfig; - let filePath = global.DEV_TEAM + "/" + "bots" + "/" + bot.repo + "/" + pProcessConfig.name; + let filePath = bot.devTeam + "/" + "bots" + "/" + bot.repo + "/" + pProcessConfig.name; filePath += "/User.Bot.js" - fileStorage.getTextFile(global.DEV_TEAM, filePath, onBotDownloaded); + fileStorage.getTextFile(bot.devTeam, filePath, onBotDownloaded); function onBotDownloaded(err, text) { @@ -56,10 +56,10 @@ } USER_BOT_MODULE.newUserBot = eval(text); // TODO This needs to be changed function - filePath = global.DEV_TEAM + "/" + "bots" + "/" + bot.repo; + filePath = bot.devTeam + "/" + "bots" + "/" + bot.repo; filePath += "/Commons.js" - fileStorage.getTextFile(global.DEV_TEAM, filePath, onCommonsDownloaded); + fileStorage.getTextFile(bot.devTeam, filePath, onCommonsDownloaded); function onCommonsDownloaded(err, text) { @@ -696,7 +696,7 @@ } function hearBeat() { - let key = global.USER_DEFINITION.bot.processes[bot.processIndex].name + '-' + global.USER_DEFINITION.bot.processes[bot.processIndex].type + '-' + global.USER_DEFINITION.bot.processes[bot.processIndex].id + let key = global.TASK_NODE.bot.processes[bot.processIndex].name + '-' + global.TASK_NODE.bot.processes[bot.processIndex].type + '-' + global.TASK_NODE.bot.processes[bot.processIndex].id let event = { seconds: (new Date()).getSeconds() diff --git a/TradingEngineProcessMainLoop.js b/TradingEngineProcessMainLoop.js index 3eadcadf0..e41ebff71 100644 --- a/TradingEngineProcessMainLoop.js +++ b/TradingEngineProcessMainLoop.js @@ -41,10 +41,10 @@ UI_COMMANDS = pUI_COMMANDS; processConfig = pProcessConfig; - let filePath = global.DEV_TEAM + "/" + "bots" + "/" + bot.repo + "/" + pProcessConfig.name + let filePath = bot.devTeam + "/" + "bots" + "/" + bot.repo + "/" + pProcessConfig.name filePath += "/User.Bot.js" - fileStorage.getTextFile(global.DEV_TEAM, filePath, onBotDownloaded); + fileStorage.getTextFile(bot.devTeam, filePath, onBotDownloaded); function onBotDownloaded(err, text) { @@ -59,10 +59,10 @@ //USER_BOT_MODULE.newUserBot = require(process.env.BOTS_PATH + '/aamasters/AAMasters/bots/AAJason-Trading-Engine-Bot/Multi-Period/User.Bot').newUserBot // Use this for a better debugging experience. You need to bring this js module to this folder in order to work. USER_BOT_MODULE.newUserBot = eval(text); // Use this for production - filePath = global.DEV_TEAM + "/" + "bots" + "/" + bot.repo; + filePath = bot.devTeam + "/" + "bots" + "/" + bot.repo; filePath += "/Commons.js" - fileStorage.getTextFile(global.DEV_TEAM, filePath, onCommonsDownloaded); + fileStorage.getTextFile(bot.devTeam, filePath, onCommonsDownloaded); function onCommonsDownloaded(err, text) { @@ -1075,7 +1075,7 @@ } function hearBeat() { - let key = global.USER_DEFINITION.bot.processes[bot.processIndex].name + '-' + global.USER_DEFINITION.bot.processes[bot.processIndex].type + '-' + global.USER_DEFINITION.bot.processes[bot.processIndex].id + let key = global.TASK_NODE.bot.processes[bot.processIndex].name + '-' + global.TASK_NODE.bot.processes[bot.processIndex].type + '-' + global.TASK_NODE.bot.processes[bot.processIndex].id let event = { seconds: (new Date()).getSeconds() diff --git a/server.js b/server.js index ac33d8bd6..940984e45 100644 --- a/server.js +++ b/server.js @@ -54,21 +54,21 @@ We read the first string sent as an argument when the process was created by the of this Task and know exactly what to run within this server instance. */ -global.USER_DEFINITION = process.argv[2] +global.TASK_NODE = process.argv[2] -if (global.USER_DEFINITION !== undefined) { - console.log('[INFO] Task Server -> server -> global.USER_DEFINITION = ' + global.USER_DEFINITION) +if (global.TASK_NODE !== undefined) { + console.log('[INFO] Task Server -> server -> global.TASK_NODE = ' + global.TASK_NODE) try { - global.USER_DEFINITION = JSON.parse(global.USER_DEFINITION) + global.TASK_NODE = JSON.parse(global.TASK_NODE) } catch (err) { - console.log('[ERROR] Task Server -> server -> global.USER_DEFINITION -> ' + err.stack) + console.log('[ERROR] Task Server -> server -> global.TASK_NODE -> ' + err.stack) } } else { // I use this section to debug in standalone mode. - let argument = ' {"type":"Task","name":"Runs Backtests, Fordwardtests & Live Trades ","bot":{"type":"Trading Engine","processes":[{"type":"Process","name":"Multi Period","code":{"devTeam":"AAMasters","bot":"AAJason","mode":"live","resumeExecution":true,"type":"Trading-Engine","exchangeName":"Poloniex","process":"Multi-Period-Daily","beginDatetime":"2019-08-01T08:00:00.000Z","timePeriod":"05-min"},"id":"1bfce24d-8c05-4be9-bd25-328f07c85265"}]},"id":"cbb13086-608d-4bb4-960a-17a81038877b"}' + let argument = '{"type":"Task","name":"Runs Backtests, Fordwardtests & Live Trades ","bot":{"type":"Trading Engine","processes":[{"type":"Process","name":"Multi Period","code":{"team":"AAMasters","bot":"AAJason","process":"Multi-Period","repo":"AAJason-Trading-Engine-Bot"},"id":"1bfce24d-8c05-4be9-bd25-328f07c85265"}]},"id":"cbb13086-608d-4bb4-960a-17a81038877b"}' try { - global.USER_DEFINITION = JSON.parse(argument) + global.TASK_NODE = JSON.parse(argument) } catch (err) { console.log(err.stack) } @@ -81,7 +81,7 @@ global.DEFINITION = require(process.env.INTER_PROCESS_FILES_PATH + '/Definition' global.WRITE_LOGS_TO_FILES = process.env.WRITE_LOGS_TO_FILES /* Default parameters can be changed by the execution configuration */ -global.EXCHANGE_NAME = process.env.EXCHANGE_NAME +global.EXCHANGE_NAME = 'Poloniex' global.MARKET = { assetA: 'USDT', assetB: 'BTC' } global.CLONE_EXECUTOR = { codeName: 'AACloud', version: '1.1' } @@ -115,12 +115,12 @@ global.EXIT_NODE_PROCESS = function exitProcess() { /* Cleaning Before Exiting. */ clearInterval(global.HEARTBEAT_INTERVAL_HANDLER) - for (let i = 0; i < global.USER_DEFINITION.bot.processes.length; i++) { - let code = global.USER_DEFINITION.bot.processes[i].code + for (let i = 0; i < global.TASK_NODE.bot.processes.length; i++) { + let code = global.TASK_NODE.bot.processes[i].code /* Delete the event handler for each process. */ - let key = code.devTeam + "-" + code.codeName + "-" + code.process + let key = code.team + "-" + code.bot + "-" + code.process let event = { reason: 'Signal Received to Terminate this Process.' } @@ -130,7 +130,7 @@ global.EXIT_NODE_PROCESS = function exitProcess() { global.SYSTEM_EVENT_HANDLER.finalize() global.SYSTEM_EVENT_HANDLER = undefined - console.log("[INFO] Task Server -> " + global.USER_DEFINITION.name + " -> EXIT_NODE_PROCESS -> Task Server Stopped."); + console.log("[INFO] Task Server -> " + global.TASK_NODE.name + " -> EXIT_NODE_PROCESS -> Task Server Stopped."); process.exit() } @@ -147,21 +147,38 @@ global.SYSTEM_EVENT_HANDLER.initialize('Task Server', bootLoader) function bootLoader() { - for (let i = 0; i < global.USER_DEFINITION.bot.processes.length; i++) { - let code = global.USER_DEFINITION.bot.processes[i].code + for (let i = 0; i < global.TASK_NODE.bot.processes.length; i++) { + let code = global.TASK_NODE.bot.processes[i].code + + /* Validate that the minimun amount of parameters required are defined. */ + + if (global.TASK_NODE.bot.processes[i].code.bot === undefined) { + console.log("[INFO] Task Server -> server -> bootLoader -> Parameter 'bot' is undefined. This process will not be executed. -> Process = " + global.TASK_NODE.bot.processes[i].name); + continue + } + + if (global.TASK_NODE.bot.processes[i].code.team === undefined) { + console.log("[INFO] Task Server -> server -> bootLoader -> Parameter 'team' is undefined. This process will not be executed. -> Process = " + global.TASK_NODE.bot.processes[i].name); + continue + } + + if (global.TASK_NODE.bot.processes[i].code.process === undefined) { + console.log("[INFO] Task Server -> server -> bootLoader -> Parameter 'process' is undefined. This process will not be executed. -> Process = " + global.TASK_NODE.bot.processes[i].name); + continue + } /* Add to the execution sequence list. */ sequenceList.push(code) /* Create the event handler for each process. This event handlers are where the status reports updated events are raised. */ - let key = code.devTeam + "-" + code.bot + "-" + code.process + let key = code.team + "-" + code.bot + "-" + code.process global.SYSTEM_EVENT_HANDLER.createEventHandler(key) } /* Heartbeat sent to the UI */ - let key = global.USER_DEFINITION.name + '-' + global.USER_DEFINITION.type + '-' + global.USER_DEFINITION.id + let key = global.TASK_NODE.name + '-' + global.TASK_NODE.type + '-' + global.TASK_NODE.id global.SYSTEM_EVENT_HANDLER.createEventHandler(key) global.HEARTBEAT_INTERVAL_HANDLER = setInterval(hearBeat, 1000) @@ -182,20 +199,20 @@ function bootLoader() { function startSequence() { - for (let processIndex = 0; processIndex < global.USER_DEFINITION.bot.processes.length; processIndex++) { + for (let processIndex = 0; processIndex < global.TASK_NODE.bot.processes.length; processIndex++) { let execution = sequenceList[processIndex]; global.STOP_TASK_GRACEFULLY = false; - execution.devTeam ? process.env.DEV_TEAM = execution.devTeam : undefined; + execution.bot ? process.env.BOT = execution.bot : undefined; execution.resumeExecution = true; - execution.type ? process.env.TYPE = execution.type : undefined; + execution.process ? process.env.PROCESS = execution.process : undefined; execution.baseAsset ? process.env.BASE_ASSET = execution.baseAsset : undefined; execution.balanceAssetA ? process.env.INITIAL_BALANCE_ASSET_A = execution.balanceAssetA : undefined; execution.balanceAssetB ? process.env.INITIAL_BALANCE_ASSET_B = execution.balanceAssetB : undefined; - execution.type === 'Trading' ? process.env.CLONE_ID = 1 : undefined; + execution.exchangeName ? global.EXCHANGE_NAME = execution.exchangeName : undefined; @@ -228,7 +245,7 @@ async function readExecutionConfiguration(execution, processIndex) { let botProcess - if (execution.type === 'Trading-Engine') { + if (global.TASK_NODE.bot.type === 'Trading Engine') { /* The Trading Engine only resumes its execution after the first sequence was completed. */ if (notFirstSequence === false) { @@ -281,17 +298,17 @@ async function readExecutionConfiguration(execution, processIndex) { } } - // General Financial Being Configuration - global.DEV_TEAM = process.env.DEV_TEAM - global.CURRENT_BOT_REPO = process.env.BOT + "-" + process.env.TYPE + "-Bot" + if (global.TASK_NODE.bot.processes[processIndex].code.repo === undefined) { + global.TASK_NODE.bot.processes[processIndex].code.repo = global.TASK_NODE.bot.processes[processIndex].code.bot + "-" + global.TASK_NODE.bot.type + "-Bot" + } if (botProcess === undefined) { botProcess = process.env.PROCESS } // Only use the .env when nothing comes at Definition.json let cloneToExecute = { enabled: "true", - devTeam: process.env.DEV_TEAM, - bot: process.env.BOT, - process: botProcess, - repo: global.CURRENT_BOT_REPO + devTeam: global.TASK_NODE.bot.processes[processIndex].code.team, + bot: global.TASK_NODE.bot.processes[processIndex].code.bot, + process: global.TASK_NODE.bot.processes[processIndex].code.process, + repo: global.TASK_NODE.bot.processes[processIndex].code.repo } global.EXECUTION_CONFIG = { From 10454e47c4ec1434995151b9990c461e8ff719b6 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Wed, 18 Sep 2019 18:46:01 +0200 Subject: [PATCH 05/13] Code Mantainance --- IndicatorBotProcessMainLoop.js | 4 +--- Root.js | 11 ++++------- SensorBotProcessMainLoop.js | 4 +--- TradingEngineProcessMainLoop.js | 4 +--- server.js | 10 +--------- 5 files changed, 8 insertions(+), 25 deletions(-) diff --git a/IndicatorBotProcessMainLoop.js b/IndicatorBotProcessMainLoop.js index abc233a36..95f453280 100644 --- a/IndicatorBotProcessMainLoop.js +++ b/IndicatorBotProcessMainLoop.js @@ -25,18 +25,16 @@ }; let processConfig; - let UI_COMMANDS; return thisObject; - function initialize(pUI_COMMANDS, pProcessConfig, callBackFunction) { + function initialize(pProcessConfig, callBackFunction) { /* This function is exactly the same in the 3 modules representing the 2 different bot types loops. */ try { if (FULL_LOG === true) { parentLogger.write(MODULE_NAME, "[INFO] initialize -> Entering function."); } - UI_COMMANDS = pUI_COMMANDS; processConfig = pProcessConfig; let filePath = bot.devTeam + "/" + "bots" + "/" + bot.repo + "/" + pProcessConfig.name diff --git a/Root.js b/Root.js index b160dbba1..6c1fdbbdb 100644 --- a/Root.js +++ b/Root.js @@ -46,11 +46,10 @@ const FULL_LOG = true; let logDisplace = "Task Server" + " "; - let UI_COMMANDS; return thisObject; - function initialize(pUI_COMMANDS, callBackFunction) { + function initialize(callBackFunction) { try { console.log(logDisplace + "Root : [INFO] initialize -> Entering function. "); @@ -95,8 +94,6 @@ } }; - UI_COMMANDS = pUI_COMMANDS; - callBackFunction(); } @@ -428,7 +425,7 @@ if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> findProcess -> runSensorBot -> pYear = " + pYear); } let extractionBotMainLoop = SENSOR_BOT_MAIN_LOOP_MODULE.newSensorBotProcessMainLoop(pBotConfig, logger); - extractionBotMainLoop.initialize(UI_COMMANDS, pProcessConfig, onInitializeReady); + extractionBotMainLoop.initialize(pProcessConfig, onInitializeReady); function onInitializeReady(err) { @@ -502,7 +499,7 @@ if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> findProcess -> runIndicatorBot -> pYear = " + pYear); } let indicatorBotMainLoop = INDICATOR_BOT_MAIN_LOOP_MODULE.newIndicatorBotProcessMainLoop(pBotConfig, logger); - indicatorBotMainLoop.initialize(UI_COMMANDS, pProcessConfig, onInitializeReady); + indicatorBotMainLoop.initialize(pProcessConfig, onInitializeReady); function onInitializeReady(err) { @@ -571,7 +568,7 @@ if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> findProcess -> runTradingEngine -> Entering function."); } let tradingEngineMainLoop = TRADING_ENGINE_MAIN_LOOP_MODULE.newTradingEngineProcessMainLoop(pBotConfig, logger); - tradingEngineMainLoop.initialize(UI_COMMANDS, pProcessConfig, onInitializeReady); + tradingEngineMainLoop.initialize(pProcessConfig, onInitializeReady); function onInitializeReady(err) { diff --git a/SensorBotProcessMainLoop.js b/SensorBotProcessMainLoop.js index b3307aba0..8360236c6 100644 --- a/SensorBotProcessMainLoop.js +++ b/SensorBotProcessMainLoop.js @@ -23,18 +23,16 @@ }; let processConfig; - let UI_COMMANDS; return thisObject; - function initialize(pUI_COMMANDS, pProcessConfig, callBackFunction) { + function initialize(pProcessConfig, callBackFunction) { /* This function is exactly the same in the 3 modules representing the 2 different bot types loops. */ try { if (FULL_LOG === true) { parentLogger.write(MODULE_NAME, "[INFO] initialize -> Entering function."); } - UI_COMMANDS = pUI_COMMANDS; processConfig = pProcessConfig; let filePath = bot.devTeam + "/" + "bots" + "/" + bot.repo + "/" + pProcessConfig.name; diff --git a/TradingEngineProcessMainLoop.js b/TradingEngineProcessMainLoop.js index e41ebff71..f99b02df4 100644 --- a/TradingEngineProcessMainLoop.js +++ b/TradingEngineProcessMainLoop.js @@ -27,18 +27,16 @@ }; let processConfig; - let UI_COMMANDS; return thisObject; - function initialize(pUI_COMMANDS, pProcessConfig, callBackFunction) { + function initialize(pProcessConfig, callBackFunction) { /* This function is exactly the same in the 3 modules representing the 2 different bot types loops. */ try { if (FULL_LOG === true) { parentLogger.write(MODULE_NAME, "[INFO] initialize -> Entering function."); } - UI_COMMANDS = pUI_COMMANDS; processConfig = pProcessConfig; let filePath = bot.devTeam + "/" + "bots" + "/" + bot.repo + "/" + pProcessConfig.name diff --git a/server.js b/server.js index 940984e45..b0f32d97b 100644 --- a/server.js +++ b/server.js @@ -370,15 +370,7 @@ function startRoot(processIndex) { const ROOT_MODULE = require(ROOT_DIR + 'Root') let root = ROOT_MODULE.newRoot() - let UI_COMMANDS = { - beginDatetime: undefined, - endDatetime: undefined, - timePeriod: undefined, - startMode: undefined, - eventHandler: undefined - } - - root.initialize(UI_COMMANDS, onInitialized) + root.initialize(onInitialized) function onInitialized() { console.log('[INFO] Task Server -> server -> startRoot -> onInitialized -> Entering function. ') From e68ece1bb23ad33500f9c250279a28183e5aa8ca Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Wed, 18 Sep 2019 19:22:50 +0200 Subject: [PATCH 06/13] More code mantainance --- IndicatorBotProcessMainLoop.js | 24 ++++++------- Root.js | 26 +++++--------- SensorBotProcessMainLoop.js | 16 ++++----- StatusDependencies.js | 4 +-- TradingEngineProcessMainLoop.js | 47 +++++++++++++++++------- server.js | 63 --------------------------------- 6 files changed, 66 insertions(+), 114 deletions(-) diff --git a/IndicatorBotProcessMainLoop.js b/IndicatorBotProcessMainLoop.js index 95f453280..fdc6d9945 100644 --- a/IndicatorBotProcessMainLoop.js +++ b/IndicatorBotProcessMainLoop.js @@ -46,7 +46,7 @@ if (err.result !== global.DEFAULT_OK_RESPONSE.result) { - parentLogger.write(MODULE_NAME, "[ERROR] initialize -> onInizialized -> onBotDownloaded -> err.message = " + err.message); + parentLogger.write(MODULE_NAME, "[ERROR] initialize -> onInizialized -> onBotDownloaded -> err = " + err.stack); callBackFunction(global.DEFAULT_FAIL_RESPONSE); return; } @@ -190,7 +190,7 @@ } default: { logger.write(MODULE_NAME, "[ERROR] run -> loop -> initializeStatusDependencies -> onInizialized -> Unhandled err.result received. -> err.result = " + err.result); - logger.write(MODULE_NAME, "[ERROR] run -> loop -> initializeStatusDependencies -> onInizialized -> Unhandled err.result received. -> err.message = " + err.message); + logger.write(MODULE_NAME, "[ERROR] run -> loop -> initializeStatusDependencies -> onInizialized -> Unhandled err.result received. -> err = " + err.stack); logger.persist(); clearInterval(fixedTimeLoopIntervalHandle); @@ -293,7 +293,7 @@ } default: { logger.write(MODULE_NAME, "[ERROR] run -> loop -> initializeDataDependencies -> onInizialized -> Unhandled err.result received. -> err.result = " + err.result); - logger.write(MODULE_NAME, "[ERROR] run -> loop -> initializeDataDependencies -> onInizialized -> Unhandled err.result received. -> err.message = " + err.message); + logger.write(MODULE_NAME, "[ERROR] run -> loop -> initializeDataDependencies -> onInizialized -> Unhandled err.result received. -> err = " + err.stack); logger.persist(); clearInterval(fixedTimeLoopIntervalHandle); @@ -381,7 +381,7 @@ return; } default: { - logger.write(MODULE_NAME, "[ERROR] run -> loop -> initializeUserBot -> onInizialized > Unhandled custom response received. -> err.message = " + err.message); + logger.write(MODULE_NAME, "[ERROR] run -> loop -> initializeUserBot -> onInizialized > Unhandled custom response received. -> err = " + err.stack); logger.persist(); clearInterval(fixedTimeLoopIntervalHandle); clearTimeout(nextLoopTimeoutHandle); @@ -394,7 +394,7 @@ } default: { logger.write(MODULE_NAME, "[ERROR] run -> loop -> initializeUserBot -> onInizialized -> Unhandled err.result received. -> err.result = " + err.result); - logger.write(MODULE_NAME, "[ERROR] run -> loop -> initializeUserBot -> onInizialized -> Unhandled err.result received. -> err.message = " + err.message); + logger.write(MODULE_NAME, "[ERROR] run -> loop -> initializeUserBot -> onInizialized -> Unhandled err.result received. -> err = " + err.stack); logger.persist(); clearInterval(fixedTimeLoopIntervalHandle); @@ -511,7 +511,7 @@ return; } default: { - logger.write(MODULE_NAME, "[ERROR] run -> loop -> startUserBot -> onFinished -> Unhandled custom response received. -> err.message = " + err.message); + logger.write(MODULE_NAME, "[ERROR] run -> loop -> startUserBot -> onFinished -> Unhandled custom response received. -> err = " + err.stack); logger.persist(); clearInterval(fixedTimeLoopIntervalHandle); clearTimeout(nextLoopTimeoutHandle); @@ -524,7 +524,7 @@ } default: { logger.write(MODULE_NAME, "[ERROR] run -> loop -> startUserBot -> onFinished -> Unhandled err.result received. -> err.result = " + err.result); - logger.write(MODULE_NAME, "[ERROR] run -> loop -> startUserBot -> onFinished -> Unhandled err.result received. -> err.message = " + err.message); + logger.write(MODULE_NAME, "[ERROR] run -> loop -> startUserBot -> onFinished -> Unhandled err.result received. -> err = " + err.stack); logger.persist(); clearInterval(fixedTimeLoopIntervalHandle); @@ -610,7 +610,7 @@ return; } default: { - logger.write(MODULE_NAME, "[ERROR] run -> loop -> intitializeProcessFramework -> onInizialized > Unhandled custom response received. -> err.message = " + err.message); + logger.write(MODULE_NAME, "[ERROR] run -> loop -> intitializeProcessFramework -> onInizialized > Unhandled custom response received. -> err = " + err.stack); logger.persist(); clearInterval(fixedTimeLoopIntervalHandle); clearTimeout(nextLoopTimeoutHandle); @@ -623,7 +623,7 @@ } default: { logger.write(MODULE_NAME, "[ERROR] run -> loop -> intitializeProcessFramework -> onInizialized -> Unhandled err.result received. -> err.result = " + err.result); - logger.write(MODULE_NAME, "[ERROR] run -> loop -> intitializeProcessFramework -> onInizialized -> Unhandled err.result received. -> err.message = " + err.message); + logger.write(MODULE_NAME, "[ERROR] run -> loop -> intitializeProcessFramework -> onInizialized -> Unhandled err.result received. -> err = " + err.stack); logger.persist(); clearInterval(fixedTimeLoopIntervalHandle); @@ -742,7 +742,7 @@ return; } default: { - logger.write(MODULE_NAME, "[ERROR] run -> loop -> startProcessFramework -> onFinished -> Unhandled custom response received. -> err.message = " + err.message); + logger.write(MODULE_NAME, "[ERROR] run -> loop -> startProcessFramework -> onFinished -> Unhandled custom response received. -> err = " + err.stack); logger.persist(); clearInterval(fixedTimeLoopIntervalHandle); clearTimeout(nextLoopTimeoutHandle); @@ -755,7 +755,7 @@ } default: { logger.write(MODULE_NAME, "[ERROR] run -> loop -> startProcessFramework -> onFinished -> Unhandled err.result received. -> err.result = " + err.result); - logger.write(MODULE_NAME, "[ERROR] run -> loop -> startProcessFramework -> onFinished -> Unhandled err.result received. -> err.message = " + err.message); + logger.write(MODULE_NAME, "[ERROR] run -> loop -> startProcessFramework -> onFinished -> Unhandled err.result received. -> err = " + err.stack); logger.persist(); clearInterval(fixedTimeLoopIntervalHandle); @@ -900,7 +900,7 @@ stopCallBack(); } } catch (err) { - logger.write(MODULE_NAME, "[ERROR] run -> loop -> shallWeStop -> err.message = " + err.message); + logger.write(MODULE_NAME, "[ERROR] run -> loop -> shallWeStop -> err = " + err.stack); logger.persist(); clearInterval(fixedTimeLoopIntervalHandle); clearTimeout(nextLoopTimeoutHandle); diff --git a/Root.js b/Root.js index 6c1fdbbdb..88486ce8d 100644 --- a/Root.js +++ b/Root.js @@ -98,7 +98,7 @@ } catch (err) { - console.log(logDisplace + "Root : [ERROR] initialize -> err.message = " + err.message); + console.log(logDisplace + "Root : [ERROR] initialize -> err = " + err.stack); return; } } @@ -123,9 +123,6 @@ const TRADING_ENGINE_MAIN_LOOP_MODULE = require('./TradingEngineProcessMainLoop'); /* Loop through all the processes configured to be run by this Node.js Instance. */ - - let cloneToExecute = global.EXECUTION_CONFIG.cloneToExecute; - /* Now we will read the config of the bot from the path we obtained at the Task Server config. */ let botConfig; @@ -154,7 +151,7 @@ try { botConfig = JSON.parse(text); - botConfig.repo = cloneToExecute.repo; + botConfig.repo = global.TASK_NODE.bot.processes[processIndex].code.repo; findProcess(processIndex); } catch (err) { console.log(logDisplace + "Root : [ERROR] start -> getBotConfig -> onInizialized -> onFileReceived -> err = " + JSON.stringify(err)); @@ -163,7 +160,7 @@ } } catch (err) { - console.log(logDisplace + "Root : [ERROR] start -> getBotConfig -> err.message = " + err.message); + console.log(logDisplace + "Root : [ERROR] start -> getBotConfig -> err = " + err.stack); return; } } @@ -173,7 +170,7 @@ try { if (FULL_LOG === true) { console.log(logDisplace + "Root : [INFO] start -> findProcess -> Entering function. "); } - botConfig.process = cloneToExecute.process; + botConfig.process = global.TASK_NODE.bot.processes[processIndex].code.process; botConfig.debug = {}; botConfig.processIndex = processIndex @@ -193,18 +190,13 @@ for (let i = 0; i < botConfig.processes.length; i++) { - if (botConfig.processes[i].name === cloneToExecute.process) { + if (botConfig.processes[i].name === global.TASK_NODE.bot.processes[processIndex].code.process) { processFound = true; - if (FULL_LOG === true) { console.log(logDisplace + "Root : [INFO] start -> findProcess -> Process found at the bot configuration file. -> cloneToExecute.process = " + cloneToExecute.process); } + if (FULL_LOG === true) { console.log(logDisplace + "Root : [INFO] start -> findProcess -> Process found at the bot configuration file. -> process = " + global.TASK_NODE.bot.processes[processIndex].code.process); } let processConfig = botConfig.processes[i]; - if (global.EXECUTION_CONFIG.timePeriod) { - processConfig.timePeriod = global.EXECUTION_CONFIG.timePeriod - } - - if (processConfig.framework !== undefined) { if (processConfig.framework.name === "Multi-Period-Daily" || processConfig.framework.name === "Multi-Period-Market" || processConfig.framework.name === "Multi-Period") { processConfig.framework.startDate.resumeExecution = true; @@ -397,7 +389,7 @@ } } catch (err) { - console.log(logDisplace + "Root : [ERROR] start -> findProcess -> Unexpected exception. -> err.message = " + err.message); + console.log(logDisplace + "Root : [ERROR] start -> findProcess -> Unexpected exception. -> err = " + err.stack); } } } @@ -405,7 +397,7 @@ if (processFound === false) { console.log(logDisplace + "Root : [ERROR] start -> findProcess -> Process listed at the configuration file of Task Server not found at the configuration file of the bot."); - console.log(logDisplace + "Root : [ERROR] start -> findProcess -> cloneToExecute.process = " + cloneToExecute.process); + console.log(logDisplace + "Root : [ERROR] start -> findProcess -> process = " + global.TASK_NODE.bot.processes[processIndex].code.process); } @@ -621,7 +613,7 @@ } } catch (err) { - console.log(logDisplace + "Root : [ERROR] start -> findProcess -> err.message = " + err.message); + console.log(logDisplace + "Root : [ERROR] start -> findProcess -> err = " + err.stack); exitProcessInstance() } } diff --git a/SensorBotProcessMainLoop.js b/SensorBotProcessMainLoop.js index 8360236c6..464793ae9 100644 --- a/SensorBotProcessMainLoop.js +++ b/SensorBotProcessMainLoop.js @@ -44,7 +44,7 @@ if (err.result !== global.DEFAULT_OK_RESPONSE.result) { - parentLogger.write(MODULE_NAME, "[ERROR] initialize -> onInizialized -> onBotDownloaded -> err.message = " + err.message); + parentLogger.write(MODULE_NAME, "[ERROR] initialize -> onInizialized -> onBotDownloaded -> err = " + err.stack); callBackFunction(global.DEFAULT_FAIL_RESPONSE); return; } @@ -189,7 +189,7 @@ } default: { logger.write(MODULE_NAME, "[ERROR] run -> loop -> initializeStatusDependencies -> onInizialized -> Unhandled err.result received. -> err.result = " + err.result); - logger.write(MODULE_NAME, "[ERROR] run -> loop -> initializeStatusDependencies -> onInizialized -> Unhandled err.result received. -> err.message = " + err.message); + logger.write(MODULE_NAME, "[ERROR] run -> loop -> initializeStatusDependencies -> onInizialized -> Unhandled err.result received. -> err = " + err.stack); logger.persist(); clearInterval(fixedTimeLoopIntervalHandle); @@ -263,7 +263,7 @@ } default: { logger.write(MODULE_NAME, "[ERROR] run -> loop -> initializeExchangeAPI -> onInizialized -> Unhandled err.result received. -> err.result = " + err.result); - logger.write(MODULE_NAME, "[ERROR] run -> loop -> initializeExchangeAPI -> onInizialized -> Unhandled err.result received. -> err.message = " + err.message); + logger.write(MODULE_NAME, "[ERROR] run -> loop -> initializeExchangeAPI -> onInizialized -> Unhandled err.result received. -> err = " + err.stack); logger.persist(); clearInterval(fixedTimeLoopIntervalHandle); @@ -359,7 +359,7 @@ return; } default: { - logger.write(MODULE_NAME, "[ERROR] run -> loop -> initializeUserBot -> onInizialized > Unhandled custom response received. -> err.message = " + err.message); + logger.write(MODULE_NAME, "[ERROR] run -> loop -> initializeUserBot -> onInizialized > Unhandled custom response received. -> err = " + err.stack); logger.persist(); clearInterval(fixedTimeLoopIntervalHandle); clearTimeout(nextLoopTimeoutHandle); @@ -372,7 +372,7 @@ } default: { logger.write(MODULE_NAME, "[ERROR] run -> loop -> initializeUserBot -> onInizialized > Unhandled err.result received. -> err.result = " + err.result); - logger.write(MODULE_NAME, "[ERROR] run -> loop -> initializeUserBot -> onInizialized > Unhandled err.result received. -> err.message = " + err.message); + logger.write(MODULE_NAME, "[ERROR] run -> loop -> initializeUserBot -> onInizialized > Unhandled err.result received. -> err = " + err.stack); logger.persist(); clearInterval(fixedTimeLoopIntervalHandle); @@ -489,7 +489,7 @@ return; } default: { - logger.write(MODULE_NAME, "[ERROR] run -> loop -> startUserBot -> onFinished > Unhandled custom response received. -> err.message = " + err.message); + logger.write(MODULE_NAME, "[ERROR] run -> loop -> startUserBot -> onFinished > Unhandled custom response received. -> err = " + err.stack); logger.persist(); clearInterval(fixedTimeLoopIntervalHandle); clearTimeout(nextLoopTimeoutHandle); @@ -502,7 +502,7 @@ } default: { logger.write(MODULE_NAME, "[ERROR] run -> loop -> startUserBot -> onFinished > Unhandled err.result received. -> err.result = " + err.result); - logger.write(MODULE_NAME, "[ERROR] run -> loop -> startUserBot -> onFinished > Unhandled err.result received. -> err.message = " + err.message); + logger.write(MODULE_NAME, "[ERROR] run -> loop -> startUserBot -> onFinished > Unhandled err.result received. -> err = " + err.stack); logger.persist(); clearInterval(fixedTimeLoopIntervalHandle); @@ -672,7 +672,7 @@ stopCallBack(); } } catch (err) { - logger.write(MODULE_NAME, "[ERROR] run -> loop -> shallWeStop -> err.message = " + err.message); + logger.write(MODULE_NAME, "[ERROR] run -> loop -> shallWeStop -> err = " + err.stack); logger.persist(); clearInterval(fixedTimeLoopIntervalHandle); clearTimeout(nextLoopTimeoutHandle); diff --git a/StatusDependencies.js b/StatusDependencies.js index 75b273431..ae1230e2c 100644 --- a/StatusDependencies.js +++ b/StatusDependencies.js @@ -66,7 +66,7 @@ } case "Status Report was never created.": { - logger.write(MODULE_NAME, "[WARN] initialize -> onLoad -> err.message = " + err.message); + logger.write(MODULE_NAME, "[WARN] initialize -> onLoad -> err = " + err.stack); logger.write(MODULE_NAME, "[WARN] initialize -> onLoad -> Report Not Found. -> bot = " + pStatusDependenciesConfig[i].bot); logger.write(MODULE_NAME, "[WARN] initialize -> onLoad -> Report Not Found. -> process = " + pStatusDependenciesConfig[i].process); addReport(); @@ -75,7 +75,7 @@ case "Status Report is corrupt.": { - logger.write(MODULE_NAME, "[WARN] initialize -> onLoad -> err.message = " + err.message); + logger.write(MODULE_NAME, "[WARN] initialize -> onLoad -> err = " + err.stack); logger.write(MODULE_NAME, "[WARN] initialize -> onLoad -> Report Not Found. -> bot = " + pStatusDependenciesConfig[i].bot); logger.write(MODULE_NAME, "[WARN] initialize -> onLoad -> Report Not Found. -> process = " + pStatusDependenciesConfig[i].process); addReport(); diff --git a/TradingEngineProcessMainLoop.js b/TradingEngineProcessMainLoop.js index f99b02df4..8d84f7e5d 100644 --- a/TradingEngineProcessMainLoop.js +++ b/TradingEngineProcessMainLoop.js @@ -48,7 +48,7 @@ if (err.result !== global.DEFAULT_OK_RESPONSE.result) { - parentLogger.write(MODULE_NAME, "[ERROR] initialize -> onInizialized -> onBotDownloaded -> err.message = " + err.message); + parentLogger.write(MODULE_NAME, "[ERROR] initialize -> onInizialized -> onBotDownloaded -> err = " + err.stack); callBackFunction(global.DEFAULT_FAIL_RESPONSE); return; } @@ -146,12 +146,35 @@ /* We are going to run the Definition comming at the event. */ global.DEFINITION = JSON.parse(message.event.definition) + if (global.DEFINITION.personalData) { + if (global.DEFINITION.personalData.exchangeAccounts) { + if (global.DEFINITION.personalData.exchangeAccounts.length > 0) { + let exchangeAccount = global.DEFINITION.personalData.exchangeAccounts[0] + if (exchangeAccount.keys) { + if (exchangeAccount.keys.length > 0) { + let key = exchangeAccount.keys[0] + + process.env.KEY = key.name + process.env.SECRET = key.code + + } + } + } + } + } + + if (process.env.KEY === undefined || process.env.SECRET === undefined) { + if (FULL_LOG === true) { logger.write(MODULE_NAME, "[WARN] run -> startLiveTrading -> Key name or Secret not provided, not possible to run the process in Live mode."); } + return + } + bot.startMode = "Live" processConfig.framework.startDate.fixedDate = new Date() processConfig.framework.startDate.resumeExecution = false; bot.multiPeriodDailyProcessDatetime = processConfig.framework.startDate.fixedDate global.STOP_PROCESSING = false bot.hasTheBotJustStarted = true + } function stopRequested() { @@ -268,7 +291,7 @@ } default: { logger.write(MODULE_NAME, "[ERROR] run -> loop -> initializeStatusDependencies -> onInizialized -> Unhandled err.result received. -> err.result = " + err.result); - logger.write(MODULE_NAME, "[ERROR] run -> loop -> initializeStatusDependencies -> onInizialized -> Unhandled err.result received. -> err.message = " + err.message); + logger.write(MODULE_NAME, "[ERROR] run -> loop -> initializeStatusDependencies -> onInizialized -> Unhandled err.result received. -> err = " + err.stack); logger.persist(); clearInterval(fixedTimeLoopIntervalHandle); @@ -342,7 +365,7 @@ } default: { logger.write(MODULE_NAME, "[ERROR] run -> loop -> initializeDataDependencies -> onInizialized -> Unhandled err.result received. -> err.result = " + err.result); - logger.write(MODULE_NAME, "[ERROR] run -> loop -> initializeDataDependencies -> onInizialized -> Unhandled err.result received. -> err.message = " + err.message); + logger.write(MODULE_NAME, "[ERROR] run -> loop -> initializeDataDependencies -> onInizialized -> Unhandled err.result received. -> err = " + err.stack); logger.persist(); clearInterval(fixedTimeLoopIntervalHandle); @@ -415,7 +438,7 @@ } default: { logger.write(MODULE_NAME, "[ERROR] run -> loop -> initializeContext -> onInizialized -> Unhandled err.result received. -> err.result = " + err.result); - logger.write(MODULE_NAME, "[ERROR] run -> loop -> initializeContext -> onInizialized -> Unhandled err.result received. -> err.message = " + err.message); + logger.write(MODULE_NAME, "[ERROR] run -> loop -> initializeContext -> onInizialized -> Unhandled err.result received. -> err = " + err.stack); logger.persist(); clearInterval(fixedTimeLoopIntervalHandle); @@ -489,7 +512,7 @@ } default: { logger.write(MODULE_NAME, "[ERROR] run -> loop -> initializeExchangeAPI -> onInizialized -> Unhandled err.result received. -> err.result = " + err.result); - logger.write(MODULE_NAME, "[ERROR] run -> loop -> initializeExchangeAPI -> onInizialized -> Unhandled err.result received. -> err.message = " + err.message); + logger.write(MODULE_NAME, "[ERROR] run -> loop -> initializeExchangeAPI -> onInizialized -> Unhandled err.result received. -> err = " + err.stack); logger.persist(); clearInterval(fixedTimeLoopIntervalHandle); @@ -596,7 +619,7 @@ } default: { logger.write(MODULE_NAME, "[ERROR] run -> loop -> initializeAssistant -> onInizialized -> Unhandled err.result received. -> err.result = " + err.result); - logger.write(MODULE_NAME, "[ERROR] run -> loop -> initializeAssistant -> onInizialized -> Unhandled err.result received. -> err.message = " + err.message); + logger.write(MODULE_NAME, "[ERROR] run -> loop -> initializeAssistant -> onInizialized -> Unhandled err.result received. -> err = " + err.stack); logger.persist(); clearInterval(fixedTimeLoopIntervalHandle); @@ -682,7 +705,7 @@ return; } default: { - logger.write(MODULE_NAME, "[ERROR] run -> loop -> intitializeProcessFramework -> onInizialized > Unhandled custom response received. -> err.message = " + err.message); + logger.write(MODULE_NAME, "[ERROR] run -> loop -> intitializeProcessFramework -> onInizialized > Unhandled custom response received. -> err = " + err.stack); logger.persist(); clearInterval(fixedTimeLoopIntervalHandle); clearTimeout(nextLoopTimeoutHandle); @@ -695,7 +718,7 @@ } default: { logger.write(MODULE_NAME, "[ERROR] run -> loop -> intitializeProcessFramework -> onInizialized -> Unhandled err.result received. -> err.result = " + err.result); - logger.write(MODULE_NAME, "[ERROR] run -> loop -> intitializeProcessFramework -> onInizialized -> Unhandled err.result received. -> err.message = " + err.message); + logger.write(MODULE_NAME, "[ERROR] run -> loop -> intitializeProcessFramework -> onInizialized -> Unhandled err.result received. -> err = " + err.stack); logger.persist(); clearInterval(fixedTimeLoopIntervalHandle); @@ -814,7 +837,7 @@ return; } default: { - logger.write(MODULE_NAME, "[ERROR] run -> loop -> startProcessFramework -> onFinished -> Unhandled custom response received. -> err.message = " + err.message); + logger.write(MODULE_NAME, "[ERROR] run -> loop -> startProcessFramework -> onFinished -> Unhandled custom response received. -> err = " + err.stack); logger.persist(); clearInterval(fixedTimeLoopIntervalHandle); clearTimeout(nextLoopTimeoutHandle); @@ -827,7 +850,7 @@ } default: { logger.write(MODULE_NAME, "[ERROR] run -> loop -> startProcessFramework -> onFinished -> Unhandled err.result received. -> err.result = " + err.result); - logger.write(MODULE_NAME, "[ERROR] run -> loop -> startProcessFramework -> onFinished -> Unhandled err.result received. -> err.message = " + err.message); + logger.write(MODULE_NAME, "[ERROR] run -> loop -> startProcessFramework -> onFinished -> Unhandled err.result received. -> err = " + err.stack); logger.persist(); clearInterval(fixedTimeLoopIntervalHandle); @@ -904,7 +927,7 @@ } default: { logger.write(MODULE_NAME, "[ERROR] run -> loop -> saveContext -> onFinished -> Unhandled err.result received. -> err.result = " + err.result); - logger.write(MODULE_NAME, "[ERROR] run -> loop -> saveContext -> onFinished -> Unhandled err.result received. -> err.message = " + err.message); + logger.write(MODULE_NAME, "[ERROR] run -> loop -> saveContext -> onFinished -> Unhandled err.result received. -> err = " + err.stack); logger.persist(); clearInterval(fixedTimeLoopIntervalHandle); @@ -1051,7 +1074,7 @@ stopCallBack(); } } catch (err) { - logger.write(MODULE_NAME, "[ERROR] run -> loop -> shallWeStop -> err.message = " + err.message); + logger.write(MODULE_NAME, "[ERROR] run -> loop -> shallWeStop -> err = " + err.stack); logger.persist(); clearInterval(fixedTimeLoopIntervalHandle); clearTimeout(nextLoopTimeoutHandle); diff --git a/server.js b/server.js index b0f32d97b..c4d5f9f20 100644 --- a/server.js +++ b/server.js @@ -216,24 +216,6 @@ function startSequence() { execution.exchangeName ? global.EXCHANGE_NAME = execution.exchangeName : undefined; - if (global.DEFINITION) { - if (global.DEFINITION.personalData) { - if (global.DEFINITION.personalData.exchangeAccounts) { - if (global.DEFINITION.personalData.exchangeAccounts.length > 0) { - let exchangeAccount = global.DEFINITION.personalData.exchangeAccounts[0] - if (exchangeAccount.keys) { - if (exchangeAccount.keys.length > 0) { - let key = exchangeAccount.keys[0] - - process.env.KEY = key.name - process.env.SECRET = key.code - - } - } - } - } - } - } readExecutionConfiguration(execution, processIndex); } @@ -303,18 +285,6 @@ async function readExecutionConfiguration(execution, processIndex) { } if (botProcess === undefined) { botProcess = process.env.PROCESS } // Only use the .env when nothing comes at Definition.json - let cloneToExecute = { - enabled: "true", - devTeam: global.TASK_NODE.bot.processes[processIndex].code.team, - bot: global.TASK_NODE.bot.processes[processIndex].code.bot, - process: global.TASK_NODE.bot.processes[processIndex].code.process, - repo: global.TASK_NODE.bot.processes[processIndex].code.repo - } - - global.EXECUTION_CONFIG = { - cloneToExecute: cloneToExecute - }; - global.CLONE_EXECUTOR = { codeName: 'AACloud', @@ -330,39 +300,6 @@ async function readExecutionConfiguration(execution, processIndex) { } } - -function getTimePeriod(timePeriod) { - if (timePeriod !== undefined) { - try { - let timePeriodMap = new Map() - timePeriodMap.set('24-hs', 86400000) - timePeriodMap.set('12-hs', 43200000) - timePeriodMap.set('08-hs', 28800000) - timePeriodMap.set('06-hs', 21600000) - timePeriodMap.set('04-hs', 14400000) - timePeriodMap.set('03-hs', 10800000) - timePeriodMap.set('02-hs', 7200000) - timePeriodMap.set('01-hs', 3600000) - timePeriodMap.set('45-min', 2700000) - timePeriodMap.set('40-min', 2400000) - timePeriodMap.set('30-min', 1800000) - timePeriodMap.set('20-min', 1200000) - timePeriodMap.set('15-min', 900000) - timePeriodMap.set('10-min', 600000) - timePeriodMap.set('05-min', 300000) - timePeriodMap.set('04-min', 240000) - timePeriodMap.set('03-min', 180000) - timePeriodMap.set('02-min', 120000) - timePeriodMap.set('01-min', 60000) - return timePeriodMap.get(timePeriod) - } catch (error) { - console.log('[WARN] Task Server -> server -> readExecutionConfiguration -> getTimePeriod -> Error: ', error) - } - } else { - return undefined - } -} - function startRoot(processIndex) { console.log('[INFO] Task Server -> server -> startRoot -> Entering function. ') From 5f53d838c23c143c70541ebc4b69e5772eb1576f Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Wed, 18 Sep 2019 19:37:33 +0200 Subject: [PATCH 07/13] More Cleaning --- TradingEngineProcessMainLoop.js | 48 +++++++++++++++++++++++++- server.js | 61 ++------------------------------- 2 files changed, 49 insertions(+), 60 deletions(-) diff --git a/TradingEngineProcessMainLoop.js b/TradingEngineProcessMainLoop.js index 8d84f7e5d..d065b14c3 100644 --- a/TradingEngineProcessMainLoop.js +++ b/TradingEngineProcessMainLoop.js @@ -107,6 +107,7 @@ processConfig.framework.startDate.resumeExecution = false; global.STOP_PROCESSING = false bot.hasTheBotJustStarted = true + setInitialBalance() /* If we can not get for any reason the initial date of the backtest, we will start at present time. */ processConfig.framework.startDate.fixedDate = new Date() @@ -174,13 +175,58 @@ bot.multiPeriodDailyProcessDatetime = processConfig.framework.startDate.fixedDate global.STOP_PROCESSING = false bot.hasTheBotJustStarted = true - + setInitialBalance() } function stopRequested() { global.STOP_PROCESSING = true } + function setInitialBalance() { + if (global.DEFINITION !== undefined) { + + /* Get the initial balance from the global.DEFINITION */ + let tradingSystem = global.DEFINITION.tradingSystem + + if (tradingSystem) { + if (tradingSystem.parameters !== undefined) { + if (tradingSystem.parameters.baseAsset !== undefined) { + let code + try { + code = JSON.parse(tradingSystem.parameters.baseAsset.code); + + if (code.name !== undefined) { + baseAsset = code.name; + if (baseAsset !== 'BTC' && baseAsset !== 'USDT') { + /* using BTC as default */ + baseAsset = 'BTC' + } + } + + if (baseAsset === 'BTC') { // NOTE: POLONIEX, the only exchange working so far, has Asset A and B inverted. We need to fix this. + if (code.initialBalance !== undefined) { + process.env.INITIAL_BALANCE_ASSET_B = code.initialBalance; + process.env.INITIAL_BALANCE_ASSET_A = 0 + } + } else { + if (code.initialBalance !== undefined) { + process.env.INITIAL_BALANCE_ASSET_A = code.initialBalance; + process.env.INITIAL_BALANCE_ASSET_B = 0 + } + } + } catch (err) { + global.DEFINITION.tradingSystem.parameters.baseAsset.error = err.message + + process.env.INITIAL_BALANCE_ASSET_A = 0 // default + process.env.INITIAL_BALANCE_ASSET_B = 0.001 // default + + } + } + } + } + } + } + loop(); function loop() { diff --git a/server.js b/server.js index c4d5f9f20..2af751565 100644 --- a/server.js +++ b/server.js @@ -77,7 +77,6 @@ else { // I use this section to debug in standalone mode. require('dotenv').config(); -global.DEFINITION = require(process.env.INTER_PROCESS_FILES_PATH + '/Definition'); global.WRITE_LOGS_TO_FILES = process.env.WRITE_LOGS_TO_FILES /* Default parameters can be changed by the execution configuration */ @@ -207,16 +206,6 @@ function startSequence() { execution.bot ? process.env.BOT = execution.bot : undefined; execution.resumeExecution = true; - execution.process ? process.env.PROCESS = execution.process : undefined; - - execution.baseAsset ? process.env.BASE_ASSET = execution.baseAsset : undefined; - execution.balanceAssetA ? process.env.INITIAL_BALANCE_ASSET_A = execution.balanceAssetA : undefined; - execution.balanceAssetB ? process.env.INITIAL_BALANCE_ASSET_B = execution.balanceAssetB : undefined; - - - execution.exchangeName ? global.EXCHANGE_NAME = execution.exchangeName : undefined; - - readExecutionConfiguration(execution, processIndex); } } @@ -233,51 +222,6 @@ async function readExecutionConfiguration(execution, processIndex) { if (notFirstSequence === false) { execution.resumeExecution = false } - - if (global.DEFINITION !== undefined) { - - botProcess = "Multi-Period" - - /* Get the initial balance from the global.DEFINITION */ - let tradingSystem = global.DEFINITION.tradingSystem - - if (tradingSystem) { - if (tradingSystem.parameters !== undefined) { - if (tradingSystem.parameters.baseAsset !== undefined) { - let code - try { - code = JSON.parse(tradingSystem.parameters.baseAsset.code); - - if (code.name !== undefined) { - baseAsset = code.name; - if (baseAsset !== 'BTC' && baseAsset !== 'USDT') { - /* using BTC as default */ - baseAsset = 'BTC' - } - } - - if (baseAsset === 'BTC') { // NOTE: POLONIEX, the only exchange working so far, has Asset A and B inverted. We need to fix this. - if (code.initialBalance !== undefined) { - process.env.INITIAL_BALANCE_ASSET_B = code.initialBalance; - process.env.INITIAL_BALANCE_ASSET_A = 0 - } - } else { - if (code.initialBalance !== undefined) { - process.env.INITIAL_BALANCE_ASSET_A = code.initialBalance; - process.env.INITIAL_BALANCE_ASSET_B = 0 - } - } - } catch (err) { - global.DEFINITION.tradingSystem.parameters.baseAsset.error = err.message - - process.env.INITIAL_BALANCE_ASSET_A = 0 // default - process.env.INITIAL_BALANCE_ASSET_B = 0.001 // default - - } - } - } - } - } } if (global.TASK_NODE.bot.processes[processIndex].code.repo === undefined) { @@ -301,17 +245,16 @@ async function readExecutionConfiguration(execution, processIndex) { } function startRoot(processIndex) { + console.log('[INFO] Task Server -> server -> startRoot -> Entering function. ') - const ROOT_DIR = './' - const ROOT_MODULE = require(ROOT_DIR + 'Root') + const ROOT_MODULE = require('./Root') let root = ROOT_MODULE.newRoot() root.initialize(onInitialized) function onInitialized() { console.log('[INFO] Task Server -> server -> startRoot -> onInitialized -> Entering function. ') - root.start(processIndex) } } From db99134e10c96b4aca5cc5000c270a40dbdf2001 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Wed, 18 Sep 2019 20:05:19 +0200 Subject: [PATCH 08/13] server module completelly cleaned up --- MultiPeriod.js | 2 +- TradingEngineProcessMainLoop.js | 4 +- server.js | 98 ++++++++------------------------- 3 files changed, 26 insertions(+), 78 deletions(-) diff --git a/MultiPeriod.js b/MultiPeriod.js index 646254c90..6a6d44f2e 100644 --- a/MultiPeriod.js +++ b/MultiPeriod.js @@ -506,7 +506,7 @@ bot.multiPeriodDailyProcessDatetime = new Date(bot.multiPeriodDailyProcessDatetime.valueOf() + ONE_DAY_IN_MILISECONDS); previousDay = new Date(bot.multiPeriodDailyProcessDatetime.valueOf() - ONE_DAY_IN_MILISECONDS); - console.log(new Date().toISOString() + " " + pad(bot.codeName, 20) + " " + pad(bot.process, 30) + " " + " bot.multiPeriodDailyProcessDatetime = " + bot.multiPeriodDailyProcessDatetime.toISOString()); + console.log(new Date().toISOString() + " " + pad(bot.codeName, 20) + " " + pad(bot.process, 30) + " " + "bot.multiPeriodDailyProcessDatetime = " + bot.multiPeriodDailyProcessDatetime.toISOString()); if (global.WRITE_LOGS_TO_FILES === 'true') { logger.newInternalLoop(bot.codeName, bot.process); diff --git a/TradingEngineProcessMainLoop.js b/TradingEngineProcessMainLoop.js index d065b14c3..d1cd78698 100644 --- a/TradingEngineProcessMainLoop.js +++ b/TradingEngineProcessMainLoop.js @@ -278,7 +278,9 @@ /* Checking if we should process this loop or not.*/ if (global.STOP_PROCESSING === true) { if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] run -> loop -> We are going to skip this Loop bacause we were requested to stop or never asked to start."); } - console.log("[INFO] run -> loop -> We are going to skip this Loop bacause we were requested to stop or never asked to start.") + + console.log(new Date().toISOString() + " " + pad(bot.codeName, 20) + " " + pad(bot.process, 30) + + " We are going to skip this Loop bacause we were requested to stop or never asked to start. "); global.SYSTEM_EVENT_HANDLER.raiseEvent('Jason-Multi-Period', 'Process Stopped') diff --git a/server.js b/server.js index 2af751565..7d63eab48 100644 --- a/server.js +++ b/server.js @@ -43,11 +43,6 @@ process.on('exit', function (code) { console.log('[INFO] Task Server -> server -> process.on.exit -> About to exit -> code = ' + code) }) -/* Local Variables */ - -let sequenceList = [] -let heartBeatInterval - /* We read the first string sent as an argument when the process was created by the Task Manager. Ther we will find the information of the identity @@ -82,7 +77,7 @@ global.WRITE_LOGS_TO_FILES = process.env.WRITE_LOGS_TO_FILES /* Default parameters can be changed by the execution configuration */ global.EXCHANGE_NAME = 'Poloniex' global.MARKET = { assetA: 'USDT', assetB: 'BTC' } -global.CLONE_EXECUTOR = { codeName: 'AACloud', version: '1.1' } +global.CLONE_EXECUTOR = { codeName: 'AACloud', version: '1.1' } // NOTE: To refactor the name of this variable you would need to go through the bots code that are using it. /* We need to count how many process instances we deployd and how many of them have already finished their job, either @@ -142,39 +137,10 @@ const EVENT_HANDLER_MODULE = require('./SystemEventHandler.js'); const IPC = require('node-ipc'); global.SYSTEM_EVENT_HANDLER = EVENT_HANDLER_MODULE.newSystemEventHandler(IPC) global.SYSTEM_EVENT_HANDLER.initialize('Task Server', bootLoader) - +global.STOP_TASK_GRACEFULLY = false; function bootLoader() { - for (let i = 0; i < global.TASK_NODE.bot.processes.length; i++) { - let code = global.TASK_NODE.bot.processes[i].code - - /* Validate that the minimun amount of parameters required are defined. */ - - if (global.TASK_NODE.bot.processes[i].code.bot === undefined) { - console.log("[INFO] Task Server -> server -> bootLoader -> Parameter 'bot' is undefined. This process will not be executed. -> Process = " + global.TASK_NODE.bot.processes[i].name); - continue - } - - if (global.TASK_NODE.bot.processes[i].code.team === undefined) { - console.log("[INFO] Task Server -> server -> bootLoader -> Parameter 'team' is undefined. This process will not be executed. -> Process = " + global.TASK_NODE.bot.processes[i].name); - continue - } - - if (global.TASK_NODE.bot.processes[i].code.process === undefined) { - console.log("[INFO] Task Server -> server -> bootLoader -> Parameter 'process' is undefined. This process will not be executed. -> Process = " + global.TASK_NODE.bot.processes[i].name); - continue - } - - /* Add to the execution sequence list. */ - sequenceList.push(code) - - /* Create the event handler for each process. This event handlers are where the status reports updated events are raised. */ - - let key = code.team + "-" + code.bot + "-" + code.process - global.SYSTEM_EVENT_HANDLER.createEventHandler(key) - } - /* Heartbeat sent to the UI */ let key = global.TASK_NODE.name + '-' + global.TASK_NODE.type + '-' + global.TASK_NODE.id @@ -191,57 +157,37 @@ function bootLoader() { global.SYSTEM_EVENT_HANDLER.raiseEvent(key, 'Heartbeat', event) } - startSequence() -} - -/* Old Run.js code follows... */ - -function startSequence() { - for (let processIndex = 0; processIndex < global.TASK_NODE.bot.processes.length; processIndex++) { - let execution = sequenceList[processIndex]; + let code = global.TASK_NODE.bot.processes[processIndex].code - global.STOP_TASK_GRACEFULLY = false; + /* Validate that the minimun amount of parameters required are defined. */ - execution.bot ? process.env.BOT = execution.bot : undefined; - execution.resumeExecution = true; - - readExecutionConfiguration(execution, processIndex); - } -} - -async function readExecutionConfiguration(execution, processIndex) { - try { - console.log("[INFO] Task Server -> server -> readExecutionConfiguration -> Entering function. "); - - let botProcess - - if (global.TASK_NODE.bot.type === 'Trading Engine') { - - /* The Trading Engine only resumes its execution after the first sequence was completed. */ - if (notFirstSequence === false) { - execution.resumeExecution = false - } + if (global.TASK_NODE.bot.processes[processIndex].code.bot === undefined) { + console.log("[INFO] Task Server -> server -> bootLoader -> Parameter 'bot' is undefined. This process will not be executed. -> Process = " + global.TASK_NODE.bot.processes[processIndex].name); + continue } + if (global.TASK_NODE.bot.processes[processIndex].code.team === undefined) { + console.log("[INFO] Task Server -> server -> bootLoader -> Parameter 'team' is undefined. This process will not be executed. -> Process = " + global.TASK_NODE.bot.processes[processIndex].name); + continue + } + + if (global.TASK_NODE.bot.processes[processIndex].code.process === undefined) { + console.log("[INFO] Task Server -> server -> bootLoader -> Parameter 'process' is undefined. This process will not be executed. -> Process = " + global.TASK_NODE.bot.processes[processIndex].name); + continue + } + + /* Create the event handler for each process. This event handlers are where the status reports updated events are raised. */ + + let key = code.team + "-" + code.bot + "-" + code.process + global.SYSTEM_EVENT_HANDLER.createEventHandler(key) + if (global.TASK_NODE.bot.processes[processIndex].code.repo === undefined) { global.TASK_NODE.bot.processes[processIndex].code.repo = global.TASK_NODE.bot.processes[processIndex].code.bot + "-" + global.TASK_NODE.bot.type + "-Bot" } - if (botProcess === undefined) { botProcess = process.env.PROCESS } // Only use the .env when nothing comes at Definition.json - - global.CLONE_EXECUTOR = { - codeName: 'AACloud', - version: '1.1' - } - startRoot(processIndex); } - - catch (err) { - console.log("[ERROR] readExecutionConfiguration -> err = " + err.stack); - console.log("[ERROR] readExecutionConfiguration -> Please verify that the Start Mode for the type of Bot configured applies to that type."); - } } function startRoot(processIndex) { From fca8c91f9b4412c366f7a998a07781c45961cbb8 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Thu, 19 Sep 2019 14:46:48 +0200 Subject: [PATCH 09/13] Bug Fixes and Improvements --- IndicatorBotProcessMainLoop.js | 22 +++---- Integrations/FileStorage.js | 113 +++++++++++++++----------------- MultiPeriodDaily.js | 2 +- Root.js | 18 ++--- SensorBotProcessMainLoop.js | 14 ++-- TradingEngineProcessMainLoop.js | 22 +++---- server.js | 2 +- 7 files changed, 92 insertions(+), 101 deletions(-) diff --git a/IndicatorBotProcessMainLoop.js b/IndicatorBotProcessMainLoop.js index fdc6d9945..ae59e3c64 100644 --- a/IndicatorBotProcessMainLoop.js +++ b/IndicatorBotProcessMainLoop.js @@ -46,7 +46,7 @@ if (err.result !== global.DEFAULT_OK_RESPONSE.result) { - parentLogger.write(MODULE_NAME, "[ERROR] initialize -> onInizialized -> onBotDownloaded -> err = " + err.stack); + parentLogger.write(MODULE_NAME, "[ERROR] initialize -> onInizialized -> onBotDownloaded -> err = " + err.message); callBackFunction(global.DEFAULT_FAIL_RESPONSE); return; } @@ -190,7 +190,7 @@ } default: { logger.write(MODULE_NAME, "[ERROR] run -> loop -> initializeStatusDependencies -> onInizialized -> Unhandled err.result received. -> err.result = " + err.result); - logger.write(MODULE_NAME, "[ERROR] run -> loop -> initializeStatusDependencies -> onInizialized -> Unhandled err.result received. -> err = " + err.stack); + logger.write(MODULE_NAME, "[ERROR] run -> loop -> initializeStatusDependencies -> onInizialized -> Unhandled err.result received. -> err = " + err.message); logger.persist(); clearInterval(fixedTimeLoopIntervalHandle); @@ -293,7 +293,7 @@ } default: { logger.write(MODULE_NAME, "[ERROR] run -> loop -> initializeDataDependencies -> onInizialized -> Unhandled err.result received. -> err.result = " + err.result); - logger.write(MODULE_NAME, "[ERROR] run -> loop -> initializeDataDependencies -> onInizialized -> Unhandled err.result received. -> err = " + err.stack); + logger.write(MODULE_NAME, "[ERROR] run -> loop -> initializeDataDependencies -> onInizialized -> Unhandled err.result received. -> err = " + err.message); logger.persist(); clearInterval(fixedTimeLoopIntervalHandle); @@ -381,7 +381,7 @@ return; } default: { - logger.write(MODULE_NAME, "[ERROR] run -> loop -> initializeUserBot -> onInizialized > Unhandled custom response received. -> err = " + err.stack); + logger.write(MODULE_NAME, "[ERROR] run -> loop -> initializeUserBot -> onInizialized > Unhandled custom response received. -> err = " + err.message); logger.persist(); clearInterval(fixedTimeLoopIntervalHandle); clearTimeout(nextLoopTimeoutHandle); @@ -394,7 +394,7 @@ } default: { logger.write(MODULE_NAME, "[ERROR] run -> loop -> initializeUserBot -> onInizialized -> Unhandled err.result received. -> err.result = " + err.result); - logger.write(MODULE_NAME, "[ERROR] run -> loop -> initializeUserBot -> onInizialized -> Unhandled err.result received. -> err = " + err.stack); + logger.write(MODULE_NAME, "[ERROR] run -> loop -> initializeUserBot -> onInizialized -> Unhandled err.result received. -> err = " + err.message); logger.persist(); clearInterval(fixedTimeLoopIntervalHandle); @@ -511,7 +511,7 @@ return; } default: { - logger.write(MODULE_NAME, "[ERROR] run -> loop -> startUserBot -> onFinished -> Unhandled custom response received. -> err = " + err.stack); + logger.write(MODULE_NAME, "[ERROR] run -> loop -> startUserBot -> onFinished -> Unhandled custom response received. -> err = " + err.message); logger.persist(); clearInterval(fixedTimeLoopIntervalHandle); clearTimeout(nextLoopTimeoutHandle); @@ -524,7 +524,7 @@ } default: { logger.write(MODULE_NAME, "[ERROR] run -> loop -> startUserBot -> onFinished -> Unhandled err.result received. -> err.result = " + err.result); - logger.write(MODULE_NAME, "[ERROR] run -> loop -> startUserBot -> onFinished -> Unhandled err.result received. -> err = " + err.stack); + logger.write(MODULE_NAME, "[ERROR] run -> loop -> startUserBot -> onFinished -> Unhandled err.result received. -> err = " + err.message); logger.persist(); clearInterval(fixedTimeLoopIntervalHandle); @@ -610,7 +610,7 @@ return; } default: { - logger.write(MODULE_NAME, "[ERROR] run -> loop -> intitializeProcessFramework -> onInizialized > Unhandled custom response received. -> err = " + err.stack); + logger.write(MODULE_NAME, "[ERROR] run -> loop -> intitializeProcessFramework -> onInizialized > Unhandled custom response received. -> err = " + err.message); logger.persist(); clearInterval(fixedTimeLoopIntervalHandle); clearTimeout(nextLoopTimeoutHandle); @@ -623,7 +623,7 @@ } default: { logger.write(MODULE_NAME, "[ERROR] run -> loop -> intitializeProcessFramework -> onInizialized -> Unhandled err.result received. -> err.result = " + err.result); - logger.write(MODULE_NAME, "[ERROR] run -> loop -> intitializeProcessFramework -> onInizialized -> Unhandled err.result received. -> err = " + err.stack); + logger.write(MODULE_NAME, "[ERROR] run -> loop -> intitializeProcessFramework -> onInizialized -> Unhandled err.result received. -> err = " + err.message); logger.persist(); clearInterval(fixedTimeLoopIntervalHandle); @@ -742,7 +742,7 @@ return; } default: { - logger.write(MODULE_NAME, "[ERROR] run -> loop -> startProcessFramework -> onFinished -> Unhandled custom response received. -> err = " + err.stack); + logger.write(MODULE_NAME, "[ERROR] run -> loop -> startProcessFramework -> onFinished -> Unhandled custom response received. -> err = " + err.message); logger.persist(); clearInterval(fixedTimeLoopIntervalHandle); clearTimeout(nextLoopTimeoutHandle); @@ -755,7 +755,7 @@ } default: { logger.write(MODULE_NAME, "[ERROR] run -> loop -> startProcessFramework -> onFinished -> Unhandled err.result received. -> err.result = " + err.result); - logger.write(MODULE_NAME, "[ERROR] run -> loop -> startProcessFramework -> onFinished -> Unhandled err.result received. -> err = " + err.stack); + logger.write(MODULE_NAME, "[ERROR] run -> loop -> startProcessFramework -> onFinished -> Unhandled err.result received. -> err = " + err.message); logger.persist(); clearInterval(fixedTimeLoopIntervalHandle); diff --git a/Integrations/FileStorage.js b/Integrations/FileStorage.js index 699797ddd..481f10264 100644 --- a/Integrations/FileStorage.js +++ b/Integrations/FileStorage.js @@ -28,6 +28,14 @@ exports.newFileStorage = function newFileStorage(logger) { 'EAI_AGAIN' ] + if (logger === undefined) { + logger = {} + function write() { + + } + logger.write = write + } + return { getTextFile, createTextFile @@ -115,72 +123,55 @@ exports.newFileStorage = function newFileStorage(logger) { } } - async function createTextFile(container, filePath, fileContent, callBackFunction) { + function createTextFile(container, filePath, fileContent, callBackFunction) { - try { - let host = await getDevTeamHost(container) - - if (host.url.indexOf('localhost') !== -1) { - let fileLocation - - if (filePath.indexOf("/Logs/") > 0) { - fileLocation = process.env.LOG_PATH + '/' + container + '/' + filePath - } else { - fileLocation = process.env.STORAGE_PATH + '/' + container + '/' + filePath - } - - logInfo('createTextFile: ' + fileLocation) - //console.log('createTextFile: ' + fileLocation) - - let directoryPath = fileLocation.substring(0, fileLocation.lastIndexOf('/') + 1); - mkDirByPathSync(directoryPath) - await writeFileAsync(fileLocation, fileContent) - callBackFunction(global.DEFAULT_OK_RESPONSE) - } else { - let response = await axios({ - url: process.env.GATEWAY_ENDPOINT_K8S, - method: 'post', - data: { - query: ` - mutation web_CreateFile($file: web_FileInput){ - web_CreateFile(file: $file) - } - `, - variables: { - file: { - container: container.toLowerCase(), - filePath, - storage: 'localStorage', - accessKey: host.ownerKey, - fileContent - } - } - } - }) - - if (!response || response.data.errors) { - let customErr = { - result: global.CUSTOM_FAIL_RESPONSE.result, - message: response.data.errors[0] - } - callBackFunction(customErr) + /* Choose path for either logs or data */ + let fileLocation + if (filePath.indexOf("/Logs/") > 0) { + fileLocation = process.env.LOG_PATH + '/' + container + '/' + filePath } else { - callBackFunction(global.DEFAULT_OK_RESPONSE) + fileLocation = process.env.STORAGE_PATH + '/' + container + '/' + filePath } - } - } catch (err) { - if (verifyRetry(err.code) && currentRetryWriteTextFile < MAX_RETRY) { - currentRetryWriteTextFile++ - logInfo('createTextFile -> Retrying connection to the server because received error: ' + err.code + '. Retry #: ' + currentRetryWriteTextFile) - createTextFile(container, filePath, fileContent, callBackFunction) - } else { - currentRetryWriteTextFile = 0 - logError('createTextFile -> error = ' + err.message) - callBackFunction(global.DEFAULT_FAIL_RESPONSE) - } + try { + + logger.write(MODULE_NAME, '[INFO] FileStorage -> createTextFile -> fileLocation: ' + fileLocation) + + /* If necesary a folder or folders are created before writing the file to disk. */ + let directoryPath = fileLocation.substring(0, fileLocation.lastIndexOf('/') + 1); + mkDirByPathSync(directoryPath) + + /* Here we actually write the file. */ + fs.writeFile(fileLocation, fileContent, onFileWriten) + + function onFileWriten(err) { + if (err) { + logger.write(MODULE_NAME, '[ERROR] FileStorage -> createTextFile -> onFileWrite -> Error writing file -> file = ' + fileLocation) + logger.write(MODULE_NAME, '[ERROR] FileStorage -> createTextFile -> onFileWrite -> Error writing file -> err = ' + err.stack) + retry() + } else { + callBackFunction(global.DEFAULT_OK_RESPONSE) + } + } + + } catch (err) { + logger.write(MODULE_NAME, '[ERROR] FileStorage -> createTextFile -> Error writing file -> file = ' + fileLocation) + logger.write(MODULE_NAME, '[ERROR] FileStorage -> createTextFile -> Error writing file -> err = ' + err.stack) + retry() + } + + function retry() { + if (currentRetryWriteTextFile < MAX_RETRY) { + currentRetryWriteTextFile++ + logger.write(MODULE_NAME, '[WARN] FileStorage -> createTextFile -> retry -> Will try to write the file again -> Retry #: ' + currentRetryWriteTextFile) + createTextFile(container, filePath, fileContent, callBackFunction) + } else { + currentRetryWriteTextFile = 0 + logger.write(MODULE_NAME, '[ERROR] FileStorage -> createTextFile -> retry -> Max retries reached. Giving up.') + callBackFunction(global.DEFAULT_FAIL_RESPONSE) + } + } } - } async function getDevTeamHost(devTeamName) { let ecosystem = await Ecosystem.getEcosystem() diff --git a/MultiPeriodDaily.js b/MultiPeriodDaily.js index 7544c5404..cbe350560 100644 --- a/MultiPeriodDaily.js +++ b/MultiPeriodDaily.js @@ -310,7 +310,7 @@ bot.multiPeriodDailyProcessDatetime = new Date(bot.multiPeriodDailyProcessDatetime.valueOf() + ONE_DAY_IN_MILISECONDS); previousDay = new Date(bot.multiPeriodDailyProcessDatetime.valueOf() - ONE_DAY_IN_MILISECONDS); - console.log(new Date().toISOString() + " " + pad(bot.codeName, 20) + " " + pad(bot.process, 30) + " " + " bot.multiPeriodDailyProcessDatetime = " + bot.multiPeriodDailyProcessDatetime.toISOString()); + console.log(new Date().toISOString() + " " + pad(bot.codeName, 20) + " " + pad(bot.process, 30) + " " + "bot.multiPeriodDailyProcessDatetime = " + bot.multiPeriodDailyProcessDatetime.toISOString()); if (global.WRITE_LOGS_TO_FILES === 'true') { logger.newInternalLoop(bot.codeName, bot.process); diff --git a/Root.js b/Root.js index 88486ce8d..0a06b1132 100644 --- a/Root.js +++ b/Root.js @@ -447,7 +447,7 @@ } else { - logger.write(MODULE_NAME, "[ERROR] start -> findProcess -> runSensorBot -> onInitializeReady -> whenStartFinishes -> err = " + err.stack); + logger.write(MODULE_NAME, "[ERROR] start -> findProcess -> runSensorBot -> onInitializeReady -> whenStartFinishes -> err = " + err.message); logger.write(MODULE_NAME, "[ERROR] start -> findProcess -> runSensorBot -> onInitializeReady -> whenStartFinishes -> Execution will be stopped. "); logger.write(MODULE_NAME, "[ERROR] start -> findProcess -> runSensorBot -> onInitializeReady -> whenStartFinishes -> Bye."); logger.write(MODULE_NAME, "[ERROR] start -> findProcess -> runSensorBot -> onInitializeReady -> whenStartFinishes -> Bot Id = " + botId); @@ -460,9 +460,9 @@ } } else { - logger.write(MODULE_NAME, "[ERROR] start -> findProcess -> runSensorBot -> onInitializeReady -> err = " + err.stack); + logger.write(MODULE_NAME, "[ERROR] start -> findProcess -> runSensorBot -> onInitializeReady -> err = " + err.message); logger.write(MODULE_NAME, "[ERROR] start -> findProcess -> runSensorBot -> onInitializeReady -> Bot will not be started. "); - console.log(logDisplace + "Root : [ERROR] start -> findProcess -> runSensorBot -> onInitializeReady -> err = " + err.stack); + console.log(logDisplace + "Root : [ERROR] start -> findProcess -> runSensorBot -> onInitializeReady -> err = " + err.message); logger.persist(); exitProcessInstance() @@ -521,7 +521,7 @@ } else { - logger.write(MODULE_NAME, "[ERROR] start -> findProcess -> runIndicatorBot -> onInitializeReady -> whenStartFinishes -> err = " + err.stack); + logger.write(MODULE_NAME, "[ERROR] start -> findProcess -> runIndicatorBot -> onInitializeReady -> whenStartFinishes -> err = " + err.message); logger.write(MODULE_NAME, "[ERROR] start -> findProcess -> runIndicatorBot -> onInitializeReady -> whenStartFinishes -> Execution will be stopped. "); logger.write(MODULE_NAME, "[ERROR] start -> findProcess -> runIndicatorBot -> onInitializeReady -> whenStartFinishes -> Bye."); logger.write(MODULE_NAME, "[ERROR] start -> findProcess -> runIndicatorBot -> onInitializeReady -> whenStartFinishes -> Bot Id = " + botId); @@ -532,9 +532,9 @@ } } else { - logger.write(MODULE_NAME, "[ERROR] start -> findProcess -> runIndicatorBot -> onInitializeReady -> err = " + err.stack); + logger.write(MODULE_NAME, "[ERROR] start -> findProcess -> runIndicatorBot -> onInitializeReady -> err = " + err.message); logger.write(MODULE_NAME, "[ERROR] start -> findProcess -> runIndicatorBot -> onInitializeReady -> Failed to initialize the bot. "); - console.log(logDisplace + "Root : [ERROR] start -> findProcess -> runIndicatorBot -> onInitializeReady -> err = " + err.stack); + console.log(logDisplace + "Root : [ERROR] start -> findProcess -> runIndicatorBot -> onInitializeReady -> err = " + err.message); logger.persist(); exitProcessInstance() } @@ -587,7 +587,7 @@ } else { - logger.write(MODULE_NAME, "[ERROR] start -> findProcess -> runTradingEngine -> onInitializeReady -> whenStartFinishes -> err = " + err.stack); + logger.write(MODULE_NAME, "[ERROR] start -> findProcess -> runTradingEngine -> onInitializeReady -> whenStartFinishes -> err = " + err.message); logger.write(MODULE_NAME, "[ERROR] start -> findProcess -> runTradingEngine -> onInitializeReady -> whenStartFinishes -> Execution will be stopped. "); logger.write(MODULE_NAME, "[ERROR] start -> findProcess -> runTradingEngine -> onInitializeReady -> whenStartFinishes -> Bye."); logger.write(MODULE_NAME, "[ERROR] start -> findProcess -> runTradingEngine -> onInitializeReady -> whenStartFinishes -> Bot Id = " + botId); @@ -598,9 +598,9 @@ } } else { - logger.write(MODULE_NAME, "[ERROR] start -> findProcess -> runTradingEngine -> onInitializeReady -> err = " + err.stack); + logger.write(MODULE_NAME, "[ERROR] start -> findProcess -> runTradingEngine -> onInitializeReady -> err = " + err.message); logger.write(MODULE_NAME, "[ERROR] start -> findProcess -> runTradingEngine -> onInitializeReady -> Failed to initialize the bot. "); - console.log(logDisplace + "Root : [ERROR] start -> findProcess -> runTradingEngine -> onInitializeReady -> err = " + err.stack); + console.log(logDisplace + "Root : [ERROR] start -> findProcess -> runTradingEngine -> onInitializeReady -> err = " + err.message); logger.persist(); exitProcessInstance() } diff --git a/SensorBotProcessMainLoop.js b/SensorBotProcessMainLoop.js index 464793ae9..35e65ba53 100644 --- a/SensorBotProcessMainLoop.js +++ b/SensorBotProcessMainLoop.js @@ -44,7 +44,7 @@ if (err.result !== global.DEFAULT_OK_RESPONSE.result) { - parentLogger.write(MODULE_NAME, "[ERROR] initialize -> onInizialized -> onBotDownloaded -> err = " + err.stack); + parentLogger.write(MODULE_NAME, "[ERROR] initialize -> onInizialized -> onBotDownloaded -> err = " + err.message); callBackFunction(global.DEFAULT_FAIL_RESPONSE); return; } @@ -189,7 +189,7 @@ } default: { logger.write(MODULE_NAME, "[ERROR] run -> loop -> initializeStatusDependencies -> onInizialized -> Unhandled err.result received. -> err.result = " + err.result); - logger.write(MODULE_NAME, "[ERROR] run -> loop -> initializeStatusDependencies -> onInizialized -> Unhandled err.result received. -> err = " + err.stack); + logger.write(MODULE_NAME, "[ERROR] run -> loop -> initializeStatusDependencies -> onInizialized -> Unhandled err.result received. -> err = " + err.message); logger.persist(); clearInterval(fixedTimeLoopIntervalHandle); @@ -263,7 +263,7 @@ } default: { logger.write(MODULE_NAME, "[ERROR] run -> loop -> initializeExchangeAPI -> onInizialized -> Unhandled err.result received. -> err.result = " + err.result); - logger.write(MODULE_NAME, "[ERROR] run -> loop -> initializeExchangeAPI -> onInizialized -> Unhandled err.result received. -> err = " + err.stack); + logger.write(MODULE_NAME, "[ERROR] run -> loop -> initializeExchangeAPI -> onInizialized -> Unhandled err.result received. -> err = " + err.message); logger.persist(); clearInterval(fixedTimeLoopIntervalHandle); @@ -359,7 +359,7 @@ return; } default: { - logger.write(MODULE_NAME, "[ERROR] run -> loop -> initializeUserBot -> onInizialized > Unhandled custom response received. -> err = " + err.stack); + logger.write(MODULE_NAME, "[ERROR] run -> loop -> initializeUserBot -> onInizialized > Unhandled custom response received. -> err = " + err.message); logger.persist(); clearInterval(fixedTimeLoopIntervalHandle); clearTimeout(nextLoopTimeoutHandle); @@ -372,7 +372,7 @@ } default: { logger.write(MODULE_NAME, "[ERROR] run -> loop -> initializeUserBot -> onInizialized > Unhandled err.result received. -> err.result = " + err.result); - logger.write(MODULE_NAME, "[ERROR] run -> loop -> initializeUserBot -> onInizialized > Unhandled err.result received. -> err = " + err.stack); + logger.write(MODULE_NAME, "[ERROR] run -> loop -> initializeUserBot -> onInizialized > Unhandled err.result received. -> err = " + err.message); logger.persist(); clearInterval(fixedTimeLoopIntervalHandle); @@ -489,7 +489,7 @@ return; } default: { - logger.write(MODULE_NAME, "[ERROR] run -> loop -> startUserBot -> onFinished > Unhandled custom response received. -> err = " + err.stack); + logger.write(MODULE_NAME, "[ERROR] run -> loop -> startUserBot -> onFinished > Unhandled custom response received. -> err = " + err.message); logger.persist(); clearInterval(fixedTimeLoopIntervalHandle); clearTimeout(nextLoopTimeoutHandle); @@ -502,7 +502,7 @@ } default: { logger.write(MODULE_NAME, "[ERROR] run -> loop -> startUserBot -> onFinished > Unhandled err.result received. -> err.result = " + err.result); - logger.write(MODULE_NAME, "[ERROR] run -> loop -> startUserBot -> onFinished > Unhandled err.result received. -> err = " + err.stack); + logger.write(MODULE_NAME, "[ERROR] run -> loop -> startUserBot -> onFinished > Unhandled err.result received. -> err = " + err.message); logger.persist(); clearInterval(fixedTimeLoopIntervalHandle); diff --git a/TradingEngineProcessMainLoop.js b/TradingEngineProcessMainLoop.js index d1cd78698..7a8cb1523 100644 --- a/TradingEngineProcessMainLoop.js +++ b/TradingEngineProcessMainLoop.js @@ -48,7 +48,7 @@ if (err.result !== global.DEFAULT_OK_RESPONSE.result) { - parentLogger.write(MODULE_NAME, "[ERROR] initialize -> onInizialized -> onBotDownloaded -> err = " + err.stack); + parentLogger.write(MODULE_NAME, "[ERROR] initialize -> onInizialized -> onBotDownloaded -> err = " + err.message); callBackFunction(global.DEFAULT_FAIL_RESPONSE); return; } @@ -339,7 +339,7 @@ } default: { logger.write(MODULE_NAME, "[ERROR] run -> loop -> initializeStatusDependencies -> onInizialized -> Unhandled err.result received. -> err.result = " + err.result); - logger.write(MODULE_NAME, "[ERROR] run -> loop -> initializeStatusDependencies -> onInizialized -> Unhandled err.result received. -> err = " + err.stack); + logger.write(MODULE_NAME, "[ERROR] run -> loop -> initializeStatusDependencies -> onInizialized -> Unhandled err.result received. -> err = " + err.message); logger.persist(); clearInterval(fixedTimeLoopIntervalHandle); @@ -413,7 +413,7 @@ } default: { logger.write(MODULE_NAME, "[ERROR] run -> loop -> initializeDataDependencies -> onInizialized -> Unhandled err.result received. -> err.result = " + err.result); - logger.write(MODULE_NAME, "[ERROR] run -> loop -> initializeDataDependencies -> onInizialized -> Unhandled err.result received. -> err = " + err.stack); + logger.write(MODULE_NAME, "[ERROR] run -> loop -> initializeDataDependencies -> onInizialized -> Unhandled err.result received. -> err = " + err.message); logger.persist(); clearInterval(fixedTimeLoopIntervalHandle); @@ -486,7 +486,7 @@ } default: { logger.write(MODULE_NAME, "[ERROR] run -> loop -> initializeContext -> onInizialized -> Unhandled err.result received. -> err.result = " + err.result); - logger.write(MODULE_NAME, "[ERROR] run -> loop -> initializeContext -> onInizialized -> Unhandled err.result received. -> err = " + err.stack); + logger.write(MODULE_NAME, "[ERROR] run -> loop -> initializeContext -> onInizialized -> Unhandled err.result received. -> err = " + err.message); logger.persist(); clearInterval(fixedTimeLoopIntervalHandle); @@ -560,7 +560,7 @@ } default: { logger.write(MODULE_NAME, "[ERROR] run -> loop -> initializeExchangeAPI -> onInizialized -> Unhandled err.result received. -> err.result = " + err.result); - logger.write(MODULE_NAME, "[ERROR] run -> loop -> initializeExchangeAPI -> onInizialized -> Unhandled err.result received. -> err = " + err.stack); + logger.write(MODULE_NAME, "[ERROR] run -> loop -> initializeExchangeAPI -> onInizialized -> Unhandled err.result received. -> err = " + err.message); logger.persist(); clearInterval(fixedTimeLoopIntervalHandle); @@ -667,7 +667,7 @@ } default: { logger.write(MODULE_NAME, "[ERROR] run -> loop -> initializeAssistant -> onInizialized -> Unhandled err.result received. -> err.result = " + err.result); - logger.write(MODULE_NAME, "[ERROR] run -> loop -> initializeAssistant -> onInizialized -> Unhandled err.result received. -> err = " + err.stack); + logger.write(MODULE_NAME, "[ERROR] run -> loop -> initializeAssistant -> onInizialized -> Unhandled err.result received. -> err = " + err.message); logger.persist(); clearInterval(fixedTimeLoopIntervalHandle); @@ -753,7 +753,7 @@ return; } default: { - logger.write(MODULE_NAME, "[ERROR] run -> loop -> intitializeProcessFramework -> onInizialized > Unhandled custom response received. -> err = " + err.stack); + logger.write(MODULE_NAME, "[ERROR] run -> loop -> intitializeProcessFramework -> onInizialized > Unhandled custom response received. -> err = " + err.message); logger.persist(); clearInterval(fixedTimeLoopIntervalHandle); clearTimeout(nextLoopTimeoutHandle); @@ -766,7 +766,7 @@ } default: { logger.write(MODULE_NAME, "[ERROR] run -> loop -> intitializeProcessFramework -> onInizialized -> Unhandled err.result received. -> err.result = " + err.result); - logger.write(MODULE_NAME, "[ERROR] run -> loop -> intitializeProcessFramework -> onInizialized -> Unhandled err.result received. -> err = " + err.stack); + logger.write(MODULE_NAME, "[ERROR] run -> loop -> intitializeProcessFramework -> onInizialized -> Unhandled err.result received. -> err = " + err.message); logger.persist(); clearInterval(fixedTimeLoopIntervalHandle); @@ -885,7 +885,7 @@ return; } default: { - logger.write(MODULE_NAME, "[ERROR] run -> loop -> startProcessFramework -> onFinished -> Unhandled custom response received. -> err = " + err.stack); + logger.write(MODULE_NAME, "[ERROR] run -> loop -> startProcessFramework -> onFinished -> Unhandled custom response received. -> err = " + err.message); logger.persist(); clearInterval(fixedTimeLoopIntervalHandle); clearTimeout(nextLoopTimeoutHandle); @@ -898,7 +898,7 @@ } default: { logger.write(MODULE_NAME, "[ERROR] run -> loop -> startProcessFramework -> onFinished -> Unhandled err.result received. -> err.result = " + err.result); - logger.write(MODULE_NAME, "[ERROR] run -> loop -> startProcessFramework -> onFinished -> Unhandled err.result received. -> err = " + err.stack); + logger.write(MODULE_NAME, "[ERROR] run -> loop -> startProcessFramework -> onFinished -> Unhandled err.result received. -> err = " + err.message); logger.persist(); clearInterval(fixedTimeLoopIntervalHandle); @@ -975,7 +975,7 @@ } default: { logger.write(MODULE_NAME, "[ERROR] run -> loop -> saveContext -> onFinished -> Unhandled err.result received. -> err.result = " + err.result); - logger.write(MODULE_NAME, "[ERROR] run -> loop -> saveContext -> onFinished -> Unhandled err.result received. -> err = " + err.stack); + logger.write(MODULE_NAME, "[ERROR] run -> loop -> saveContext -> onFinished -> Unhandled err.result received. -> err = " + err.message); logger.persist(); clearInterval(fixedTimeLoopIntervalHandle); diff --git a/server.js b/server.js index 7d63eab48..0663b0f3d 100644 --- a/server.js +++ b/server.js @@ -61,7 +61,7 @@ if (global.TASK_NODE !== undefined) { } else { // I use this section to debug in standalone mode. - let argument = '{"type":"Task","name":"Runs Backtests, Fordwardtests & Live Trades ","bot":{"type":"Trading Engine","processes":[{"type":"Process","name":"Multi Period","code":{"team":"AAMasters","bot":"AAJason","process":"Multi-Period","repo":"AAJason-Trading-Engine-Bot"},"id":"1bfce24d-8c05-4be9-bd25-328f07c85265"}]},"id":"cbb13086-608d-4bb4-960a-17a81038877b"}' + let argument = '{"type":"Task","name":"Runs Backtests, Fordwardtests & Live Trades ","bot":{"type":"Trading Engine","processes":[{"type":"Process","name":"Multi Period","code":{"team":"AAMasters","bot":"AAJason","process":"Multi-Period","repo":"AAJason-Trading-Engine-Bot"},"id":"4748c8c4-4d19-4076-96b2-e9c06524fbb3"}]},"id":"561bac18-fc78-464a-90c5-79fd821fc633"}' try { global.TASK_NODE = JSON.parse(argument) } catch (err) { From 8a5edf831c4d4a162c8033dd96062aea68dce511 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Thu, 19 Sep 2019 15:23:02 +0200 Subject: [PATCH 10/13] Loophealth check only if there is a waitime set --- IndicatorBotProcessMainLoop.js | 8 ++++++-- SensorBotProcessMainLoop.js | 8 ++++++-- TradingEngineProcessMainLoop.js | 8 ++++++-- 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/IndicatorBotProcessMainLoop.js b/IndicatorBotProcessMainLoop.js index ae59e3c64..30f83007b 100644 --- a/IndicatorBotProcessMainLoop.js +++ b/IndicatorBotProcessMainLoop.js @@ -826,7 +826,9 @@ switch (nextWaitTime) { case 'Normal': { if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] run -> loop -> loopControl -> Restarting Loop in " + (processConfig.normalWaitTime / 1000) + " seconds."); } - checkLoopHealthHandle = setTimeout(checkLoopHealth, processConfig.deadWaitTime * 5, bot.loopCounter); + if (processConfig.deadWaitTime > 0) { + checkLoopHealthHandle = setTimeout(checkLoopHealth, processConfig.deadWaitTime, bot.loopCounter); + } nextLoopTimeoutHandle = setTimeout(loop, processConfig.normalWaitTime); if(global.WRITE_LOGS_TO_FILES === 'true'){ logger.persist(); @@ -835,7 +837,9 @@ break; case 'Retry': { if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] run -> loop -> loopControl -> Restarting Loop in " + (processConfig.retryWaitTime / 1000) + " seconds."); } - checkLoopHealthHandle = setTimeout(checkLoopHealth, processConfig.retryWaitTime * 5, bot.loopCounter); + if (processConfig.deadWaitTime > 0) { + checkLoopHealthHandle = setTimeout(checkLoopHealth, processConfig.deadWaitTime, bot.loopCounter); + } nextLoopTimeoutHandle = setTimeout(loop, processConfig.retryWaitTime); logger.persist(); } diff --git a/SensorBotProcessMainLoop.js b/SensorBotProcessMainLoop.js index 35e65ba53..4fd528f22 100644 --- a/SensorBotProcessMainLoop.js +++ b/SensorBotProcessMainLoop.js @@ -578,14 +578,18 @@ case 'Normal': { if (bot.runAtFixedInterval === true) { if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] run -> loop -> loopControl -> Fixed Interval Normal exit point reached."); } - checkLoopHealthHandle = setTimeout(checkLoopHealth, bot.fixedInterval * 5, bot.loopCounter); + if (processConfig.deadWaitTime > 0) { + checkLoopHealthHandle = setTimeout(checkLoopHealth, processConfig.deadWaitTime, bot.loopCounter); + } if(global.WRITE_LOGS_TO_FILES === 'true'){ logger.persist(); } return; } else { if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] run -> loop -> loopControl -> Restarting Loop in " + (processConfig.normalWaitTime / 1000) + " seconds."); } - checkLoopHealthHandle = setTimeout(checkLoopHealth, processConfig.deadWaitTime * 5, bot.loopCounter); + if (processConfig.deadWaitTime > 0) { + checkLoopHealthHandle = setTimeout(checkLoopHealth, processConfig.deadWaitTime, bot.loopCounter); + } nextLoopTimeoutHandle = setTimeout(loop, processConfig.normalWaitTime); if(global.WRITE_LOGS_TO_FILES === 'true'){ logger.persist(); diff --git a/TradingEngineProcessMainLoop.js b/TradingEngineProcessMainLoop.js index 7a8cb1523..da2c27630 100644 --- a/TradingEngineProcessMainLoop.js +++ b/TradingEngineProcessMainLoop.js @@ -1048,7 +1048,9 @@ switch (nextWaitTime) { case 'Normal': { if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] run -> loop -> loopControl -> Restarting Loop in " + (processConfig.normalWaitTime / 1000) + " seconds."); } - checkLoopHealthHandle = setTimeout(checkLoopHealth, processConfig.deadWaitTime * 5, bot.loopCounter); + if (processConfig.deadWaitTime > 0) { + checkLoopHealthHandle = setTimeout(checkLoopHealth, processConfig.deadWaitTime, bot.loopCounter); + } nextLoopTimeoutHandle = setTimeout(loop, processConfig.normalWaitTime); if (global.WRITE_LOGS_TO_FILES === 'true') { logger.persist(); @@ -1057,7 +1059,9 @@ break; case 'Retry': { if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] run -> loop -> loopControl -> Restarting Loop in " + (processConfig.retryWaitTime / 1000) + " seconds."); } - checkLoopHealthHandle = setTimeout(checkLoopHealth, processConfig.retryWaitTime * 5, bot.loopCounter); + if (processConfig.deadWaitTime > 0) { + checkLoopHealthHandle = setTimeout(checkLoopHealth, processConfig.deadWaitTime, bot.loopCounter); + } nextLoopTimeoutHandle = setTimeout(loop, processConfig.retryWaitTime); logger.persist(); } From 074f18baec1906c760108f697f369565bb7eb3fc Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Fri, 20 Sep 2019 15:16:52 +0200 Subject: [PATCH 11/13] Task Ruuning and Stopped events handled --- server.js | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/server.js b/server.js index 0663b0f3d..1e4bd36b4 100644 --- a/server.js +++ b/server.js @@ -40,6 +40,16 @@ process.on('unhandledRejection', (reason, p) => { }) process.on('exit', function (code) { + + /* We send an event signaling that the Task is being terminated. */ + + let key = global.TASK_NODE.name + '-' + global.TASK_NODE.type + '-' + global.TASK_NODE.id + + global.SYSTEM_EVENT_HANDLER.raiseEvent(key, 'Task Stopped') + global.SYSTEM_EVENT_HANDLER.deleteEventHandler(key) + global.SYSTEM_EVENT_HANDLER.finalize() + global.SYSTEM_EVENT_HANDLER = undefined + console.log('[INFO] Task Server -> server -> process.on.exit -> About to exit -> code = ' + code) }) @@ -69,7 +79,6 @@ else { // I use this section to debug in standalone mode. } } - require('dotenv').config(); global.WRITE_LOGS_TO_FILES = process.env.WRITE_LOGS_TO_FILES @@ -122,8 +131,6 @@ global.EXIT_NODE_PROCESS = function exitProcess() { global.SYSTEM_EVENT_HANDLER.deleteEventHandler(key) } - global.SYSTEM_EVENT_HANDLER.finalize() - global.SYSTEM_EVENT_HANDLER = undefined console.log("[INFO] Task Server -> " + global.TASK_NODE.name + " -> EXIT_NODE_PROCESS -> Task Server Stopped."); process.exit() @@ -146,6 +153,7 @@ function bootLoader() { let key = global.TASK_NODE.name + '-' + global.TASK_NODE.type + '-' + global.TASK_NODE.id global.SYSTEM_EVENT_HANDLER.createEventHandler(key) + global.SYSTEM_EVENT_HANDLER.raiseEvent(key, 'Task Running') global.HEARTBEAT_INTERVAL_HANDLER = setInterval(hearBeat, 1000) function hearBeat() { From 835ab7fc31b8c1e666f5b5eb861139bd4bebb711 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Fri, 20 Sep 2019 16:28:25 +0200 Subject: [PATCH 12/13] Stopping Processes correctly --- StatusReport.js | 5 ----- server.js | 14 ++++++++------ 2 files changed, 8 insertions(+), 11 deletions(-) diff --git a/StatusReport.js b/StatusReport.js index 51d4778ff..7f6fcc120 100644 --- a/StatusReport.js +++ b/StatusReport.js @@ -71,11 +71,6 @@ function responseCallBack(message) { if (message.result !== global.DEFAULT_OK_RESPONSE.result) { - logger.write(MODULE_NAME, "[ERROR] initialize -> Could not register event listener for event 'Status Report Updated' -> Message = " + message); - let event = { - reason: 'This process depends on ' + key + ' which is currently not running.' - } - global.SYSTEM_EVENT_HANDLER.raiseEvent(key, 'Process Terminated', event) callBackFunction(global.DEFAULT_FAIL_RESPONSE); } } diff --git a/server.js b/server.js index 1e4bd36b4..483ceb216 100644 --- a/server.js +++ b/server.js @@ -45,7 +45,7 @@ process.on('exit', function (code) { let key = global.TASK_NODE.name + '-' + global.TASK_NODE.type + '-' + global.TASK_NODE.id - global.SYSTEM_EVENT_HANDLER.raiseEvent(key, 'Task Stopped') + global.SYSTEM_EVENT_HANDLER.raiseEvent(key, 'Stopped') // Meaning Task Stopped global.SYSTEM_EVENT_HANDLER.deleteEventHandler(key) global.SYSTEM_EVENT_HANDLER.finalize() global.SYSTEM_EVENT_HANDLER = undefined @@ -124,11 +124,13 @@ global.EXIT_NODE_PROCESS = function exitProcess() { /* Delete the event handler for each process. */ let key = code.team + "-" + code.bot + "-" + code.process - let event = { - reason: 'Signal Received to Terminate this Process.' - } - global.SYSTEM_EVENT_HANDLER.raiseEvent(key, 'Process Terminated', event) + global.SYSTEM_EVENT_HANDLER.deleteEventHandler(key) + + let process = global.TASK_NODE.bot.processes[i] + + key = process.name + '-' + process.type + '-' + process.id + global.SYSTEM_EVENT_HANDLER.raiseEvent(key, 'Stopped') // Meaning Process Stopped } console.log("[INFO] Task Server -> " + global.TASK_NODE.name + " -> EXIT_NODE_PROCESS -> Task Server Stopped."); @@ -153,7 +155,7 @@ function bootLoader() { let key = global.TASK_NODE.name + '-' + global.TASK_NODE.type + '-' + global.TASK_NODE.id global.SYSTEM_EVENT_HANDLER.createEventHandler(key) - global.SYSTEM_EVENT_HANDLER.raiseEvent(key, 'Task Running') + global.SYSTEM_EVENT_HANDLER.raiseEvent(key, 'Running') // Meaning Task Running global.HEARTBEAT_INTERVAL_HANDLER = setInterval(hearBeat, 1000) function hearBeat() { From 5c6b6bdf15f9f0d4d8d8e125f2f1d7aa57a8b9d2 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Fri, 20 Sep 2019 16:29:33 +0200 Subject: [PATCH 13/13] 1 min to exit --- server.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/server.js b/server.js index 483ceb216..d007d0daa 100644 --- a/server.js +++ b/server.js @@ -108,8 +108,8 @@ process.on('message', message => { There are some process that might no be able to end grafully, for example the ones schedulle to process information in a future day or month. In order to be sure that the process will be terminated, we schedulle one forced exit in 2 minutes from now. */ - console.log('[INFO] Task Server -> server -> process.on -> Executing order received from Task Manager to Stop this Task. Nodejs process will be exited in less than 2 minutes.') - setTimeout(global.EXIT_NODE_PROCESS, 120000); + console.log('[INFO] Task Server -> server -> process.on -> Executing order received from Task Manager to Stop this Task. Nodejs process will be exited in less than 1 minutes.') + setTimeout(global.EXIT_NODE_PROCESS, 60000); } });