From 14f20587302138d06faa7148ac812d19c01698cf Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Wed, 25 Nov 2020 17:02:33 +0100 Subject: [PATCH] More reorganizing --- Client/package.json | 4 +-- Client/taskManagerServer.js | 2 +- TaskServer/.vscode/launch.json | 2 +- TaskServer/NodeJsProcess.js | 12 ++++---- TaskServer/{server.js => Task.js} | 48 +++++++++++++++---------------- 5 files changed, 33 insertions(+), 35 deletions(-) rename TaskServer/{server.js => Task.js} (61%) diff --git a/Client/package.json b/Client/package.json index 4970dada5..654313805 100644 --- a/Client/package.json +++ b/Client/package.json @@ -1,8 +1,8 @@ { - "name": "client", + "name": "Client", "version": "0.0.6", "description": "BackendServer", - "main": "server.js", + "main": "client.js", "author": { "name": "Luis-Fernando-Molina" }, diff --git a/Client/taskManagerServer.js b/Client/taskManagerServer.js index 47919400e..22185d53b 100644 --- a/Client/taskManagerServer.js +++ b/Client/taskManagerServer.js @@ -64,7 +64,7 @@ //console.log('[INFO] Client -> Task Manager Server -> runTask -> Task Name = ' + message.event.taskName) //console.log('[INFO] Client -> Task Manager Server -> runTask -> Task Id = ' + message.event.taskId) - let path = process.env.TASK_SERVER_PATH + '/server.js' + let path = process.env.TASK_SERVER_PATH + '/Task.js' /* Workarround to avoid having the same debug port at the forked process which makes it crash. */ for (let i = 0; i < process.execArgv.length; i++) { diff --git a/TaskServer/.vscode/launch.json b/TaskServer/.vscode/launch.json index 278e5c6a9..778f8dcea 100644 --- a/TaskServer/.vscode/launch.json +++ b/TaskServer/.vscode/launch.json @@ -11,7 +11,7 @@ "skipFiles": [ "/**" ], - "program": "${workspaceFolder}\\server.js" + "program": "${workspaceFolder}\\Task.js" } ] } \ No newline at end of file diff --git a/TaskServer/NodeJsProcess.js b/TaskServer/NodeJsProcess.js index b8e6fa890..7d329e865 100644 --- a/TaskServer/NodeJsProcess.js +++ b/TaskServer/NodeJsProcess.js @@ -9,15 +9,15 @@ exports.newNodeJsProcess = function newNodeJsProcess() { function initialize() { process.on('uncaughtException', function (err) { - console.log('[ERROR] Task Server -> server -> uncaughtException -> err.message = ' + err.message) - console.log('[ERROR] Task Server -> server -> uncaughtException -> err.stack = ' + err.stack) + console.log('[ERROR] Task Server -> Node JS Process -> uncaughtException -> err.message = ' + err.message) + console.log('[ERROR] Task Server -> Node JS Process -> uncaughtException -> err.stack = ' + err.stack) console.log(err.stack) global.EXIT_NODE_PROCESS() }) process.on('unhandledRejection', (reason, p) => { - console.log('[ERROR] Task Server -> server -> unhandledRejection -> reason = ' + JSON.stringify(reason)) - console.log('[ERROR] Task Server -> server -> unhandledRejection -> p = ' + JSON.stringify(p)) + console.log('[ERROR] Task Server -> Node JS Process -> unhandledRejection -> reason = ' + JSON.stringify(reason)) + console.log('[ERROR] Task Server -> Node JS Process -> unhandledRejection -> p = ' + JSON.stringify(p)) console.log(reason.stack) global.EXIT_NODE_PROCESS() }) @@ -33,7 +33,7 @@ exports.newNodeJsProcess = function newNodeJsProcess() { global.EVENT_SERVER_CLIENT_MODULE = undefined } - //console.log('[INFO] Task Server -> server -> process.on.exit -> About to exit -> config = ' + config) + //console.log('[INFO] Task Server -> Node JS Process -> process.on.exit -> About to exit -> config = ' + config) }) /* Here we listen for the message to stop this Task / Process comming from the Task Manager, which is the paret of this node js process. */ @@ -47,7 +47,7 @@ exports.newNodeJsProcess = function newNodeJsProcess() { In order to be sure that the process will be terminated, we schedulle one forced exit in 2 minutes from now. */ let key = global.TASK_NODE.name + '-' + global.TASK_NODE.type + '-' + global.TASK_NODE.id - console.log('[INFO] Task Server -> server -> process.on -> Stopping Task ' + key + '. Nodejs process will be exited in less than 1 minute.') + console.log('[INFO] Task Server -> Node JS Process -> process.on -> Stopping Task ' + key + '. Nodejs process will be exited in less than 1 minute.') setTimeout(global.EXIT_NODE_PROCESS, 60000); } }); diff --git a/TaskServer/server.js b/TaskServer/Task.js similarity index 61% rename from TaskServer/server.js rename to TaskServer/Task.js index 786e33d18..9c2bbd1e8 100644 --- a/TaskServer/server.js +++ b/TaskServer/Task.js @@ -23,7 +23,7 @@ function preLoader() { if (taskId !== undefined) { /* The Task Manager sent the info via a process argument. In this case we listen to an event with the Task Info that should be emitted at the UI */ try { - //console.log('[INFO] Task Server -> server -> preLoader -> Listening to starting event -> key = ' + 'Task Server - ' + taskId) + //console.log('[INFO] Task Server -> Task -> preLoader -> Listening to starting event -> key = ' + 'Task Server - ' + taskId) global.EVENT_SERVER_CLIENT_MODULE.listenToEvent('Task Server - ' + taskId, 'Run Task', undefined, 'Task Server - ' + taskId, undefined, eventReceived) global.EVENT_SERVER_CLIENT_MODULE.raiseEvent('Task Manager - ' + taskId, 'Nodejs Process Ready for Task') function eventReceived(message) { @@ -34,12 +34,12 @@ function preLoader() { global.TASK_NETWORK = JSON.parse(message.event.networkDefinition) bootLoader() } catch (err) { - console.log('[ERROR] Task Server -> server -> preLoader -> eventReceived -> ' + err.stack) + console.log('[ERROR] Task Server -> Task -> preLoader -> eventReceived -> ' + err.stack) } } } catch (err) { - console.log('[ERROR] Task Server -> server -> preLoader -> global.TASK_NODE -> ' + err.stack) - console.log('[ERROR] Task Server -> server -> preLoader -> global.TASK_NODE = ' + JSON.stringify(global.TASK_NODE).substring(0, 1000)) + console.log('[ERROR] Task Server -> Task -> preLoader -> global.TASK_NODE -> ' + err.stack) + console.log('[ERROR] Task Server -> Task -> preLoader -> global.TASK_NODE = ' + JSON.stringify(global.TASK_NODE).substring(0, 1000)) } } else { @@ -59,12 +59,12 @@ function preLoader() { bootLoader() } catch (err) { - console.log('[ERROR] Task Server -> server -> preLoader -> startDebugging -> ' + err.stack) + console.log('[ERROR] Task Server -> Task -> preLoader -> startDebugging -> ' + err.stack) } } } catch (err) { - console.log('[ERROR] Task Server -> server -> preLoader -> global.TASK_NODE -> ' + err.stack) - console.log('[ERROR] Task Server -> server -> preLoader -> global.TASK_NODE = ' + JSON.stringify(global.TASK_NODE).substring(0, 1000)) + console.log('[ERROR] Task Server -> Task -> preLoader -> global.TASK_NODE -> ' + err.stack) + console.log('[ERROR] Task Server -> Task -> preLoader -> global.TASK_NODE = ' + JSON.stringify(global.TASK_NODE).substring(0, 1000)) } } @@ -104,84 +104,84 @@ function bootLoader() { /* Validate that the minimun amount of input required are defined. */ if (global.TASK_NODE.parentNode === undefined) { - console.log("[ERROR] Task Server -> server -> bootLoader -> Task without a Task Manager. This process will not be executed. -> Process Instance = " + JSON.stringify(global.TASK_NODE.bot.processes[processIndex])); + console.log("[ERROR] Task Server -> Task -> bootLoader -> Task without a Task Manager. This process will not be executed. -> Process Instance = " + JSON.stringify(global.TASK_NODE.bot.processes[processIndex])); continue } if (global.TASK_NODE.parentNode.parentNode === undefined) { - console.log("[ERROR] Task Server -> server -> bootLoader -> Task Manager without Mine Tasks. This process will not be executed. -> Process Instance = " + JSON.stringify(global.TASK_NODE.bot.processes[processIndex])); + console.log("[ERROR] Task Server -> Task -> bootLoader -> Task Manager without Mine Tasks. This process will not be executed. -> Process Instance = " + JSON.stringify(global.TASK_NODE.bot.processes[processIndex])); continue } if (global.TASK_NODE.parentNode.parentNode.parentNode === undefined) { - console.log("[ERROR] Task Server -> server -> bootLoader -> Mine Tasks without Market Tasks. This process will not be executed. -> Process Instance = " + JSON.stringify(global.TASK_NODE.bot.processes[processIndex])); + console.log("[ERROR] Task Server -> Task -> bootLoader -> Mine Tasks without Market Tasks. This process will not be executed. -> Process Instance = " + JSON.stringify(global.TASK_NODE.bot.processes[processIndex])); continue } if (global.TASK_NODE.parentNode.parentNode.parentNode.referenceParent === undefined) { - console.log("[ERROR] Task Server -> server -> bootLoader -> Market Tasks without a Market. This process will not be executed. -> Process Instance = " + JSON.stringify(global.TASK_NODE.bot.processes[processIndex])); + console.log("[ERROR] Task Server -> Task -> bootLoader -> Market Tasks without a Market. This process will not be executed. -> Process Instance = " + JSON.stringify(global.TASK_NODE.bot.processes[processIndex])); continue } global.MARKET_NODE = global.TASK_NODE.parentNode.parentNode.parentNode.referenceParent if (global.MARKET_NODE.parentNode === undefined) { - console.log("[ERROR] Task Server -> server -> bootLoader -> Market without a Parent. This process will not be executed. -> Process Instance = " + JSON.stringify(global.MARKET_NODE)); + console.log("[ERROR] Task Server -> Task -> bootLoader -> Market without a Parent. This process will not be executed. -> Process Instance = " + JSON.stringify(global.MARKET_NODE)); continue } if (global.MARKET_NODE.parentNode.parentNode === undefined) { - console.log("[ERROR] Task Server -> server -> bootLoader -> Exchange Markets without a Parent. This process will not be executed. -> Process Instance = " + JSON.stringify(global.MARKET_NODE.parentNode)); + console.log("[ERROR] Task Server -> Task -> bootLoader -> Exchange Markets without a Parent. This process will not be executed. -> Process Instance = " + JSON.stringify(global.MARKET_NODE.parentNode)); continue } if (global.MARKET_NODE.baseAsset === undefined) { - console.log("[ERROR] Task Server -> server -> bootLoader -> Market without a Base Asset. This process will not be executed. -> Process Instance = " + JSON.stringify(global.MARKET_NODE)); + console.log("[ERROR] Task Server -> Task -> bootLoader -> Market without a Base Asset. This process will not be executed. -> Process Instance = " + JSON.stringify(global.MARKET_NODE)); continue } if (global.MARKET_NODE.quotedAsset === undefined) { - console.log("[ERROR] Task Server -> server -> bootLoader -> Market without a Quoted Asset. This process will not be executed. -> Process Instance = " + JSON.stringify(global.MARKET_NODE)); + console.log("[ERROR] Task Server -> Task -> bootLoader -> Market without a Quoted Asset. This process will not be executed. -> Process Instance = " + JSON.stringify(global.MARKET_NODE)); continue } if (global.MARKET_NODE.baseAsset.referenceParent === undefined) { - console.log("[ERROR] Task Server -> server -> bootLoader -> Base Asset without a Reference Parent. This process will not be executed. -> Process Instance = " + JSON.stringify(global.MARKET_NODE.baseAsset)); + console.log("[ERROR] Task Server -> Task -> bootLoader -> Base Asset without a Reference Parent. This process will not be executed. -> Process Instance = " + JSON.stringify(global.MARKET_NODE.baseAsset)); continue } if (global.MARKET_NODE.quotedAsset.referenceParent === undefined) { - console.log("[ERROR] Task Server -> server -> bootLoader -> Quoted Asset without a Reference Parent. This process will not be executed. -> Process Instance = " + JSON.stringify(global.MARKET_NODE.quotedAsset)); + console.log("[ERROR] Task Server -> Task -> bootLoader -> Quoted Asset without a Reference Parent. This process will not be executed. -> Process Instance = " + JSON.stringify(global.MARKET_NODE.quotedAsset)); continue } if (global.TASK_NODE.bot.processes[processIndex].referenceParent === undefined) { - console.log("[ERROR] Task Server -> server -> bootLoader -> Process Instance without a Reference Parent. This process will not be executed. -> Process Instance = " + JSON.stringify(global.TASK_NODE.bot.processes[processIndex])); + console.log("[ERROR] Task Server -> Task -> bootLoader -> Process Instance without a Reference Parent. This process will not be executed. -> Process Instance = " + JSON.stringify(global.TASK_NODE.bot.processes[processIndex])); continue } if (global.TASK_NODE.bot.processes[processIndex].referenceParent.parentNode === undefined) { - console.log("[ERROR] Task Server -> server -> bootLoader -> Process Definition without parent Bot Definition. -> Process Definition = " + JSON.stringify(global.TASK_NODE.bot.processes[processIndex].referenceParent)); + console.log("[ERROR] Task Server -> Task -> bootLoader -> Process Definition without parent Bot Definition. -> Process Definition = " + JSON.stringify(global.TASK_NODE.bot.processes[processIndex].referenceParent)); continue } if (global.TASK_NODE.bot.processes[processIndex].referenceParent.parentNode.parentNode === undefined) { - console.log("[ERROR] Task Server -> server -> bootLoader -> Bot Definition without parent Data Mine. -> Bot Definition = " + JSON.stringify(global.TASK_NODE.bot.processes[processIndex].referenceParent.parentNode)); + console.log("[ERROR] Task Server -> Task -> bootLoader -> Bot Definition without parent Data Mine. -> Bot Definition = " + JSON.stringify(global.TASK_NODE.bot.processes[processIndex].referenceParent.parentNode)); continue } if (global.TASK_NODE.bot.processes[processIndex].referenceParent.config.codeName === undefined) { - console.log("[ERROR] Task Server -> server -> bootLoader -> Process Definition without a codeName defined. -> Process Definition = " + JSON.stringify(global.TASK_NODE.bot.processes[processIndex].referenceParent)); + console.log("[ERROR] Task Server -> Task -> bootLoader -> Process Definition without a codeName defined. -> Process Definition = " + JSON.stringify(global.TASK_NODE.bot.processes[processIndex].referenceParent)); continue } if (global.TASK_NODE.bot.processes[processIndex].referenceParent.parentNode.config.codeName === undefined) { - console.log("[ERROR] Task Server -> server -> bootLoader -> Bot Definition without a codeName defined. -> Bot Definition = " + JSON.stringify(global.TASK_NODE.bot.processes[processIndex].referenceParent.parentNode)); + console.log("[ERROR] Task Server -> Task -> bootLoader -> Bot Definition without a codeName defined. -> Bot Definition = " + JSON.stringify(global.TASK_NODE.bot.processes[processIndex].referenceParent.parentNode)); continue } if (global.TASK_NODE.bot.processes[processIndex].referenceParent.parentNode.parentNode.config.codeName === undefined) { - console.log("[ERROR] Task Server -> server -> bootLoader -> Data Mine without a codeName defined. -> Data Mine Definition = " + JSON.stringify(global.TASK_NODE.bot.processes[processIndex].referenceParent.parentNode.parentNode)); + console.log("[ERROR] Task Server -> Task -> bootLoader -> Data Mine without a codeName defined. -> Data Mine Definition = " + JSON.stringify(global.TASK_NODE.bot.processes[processIndex].referenceParent.parentNode.parentNode)); continue } @@ -191,8 +191,6 @@ function bootLoader() { function startRoot(processIndex) { - // console.log('[INFO] Task Server -> server -> startRoot -> Entering function. ') - const ROOT_MODULE = require('./Root') let root = ROOT_MODULE.newRoot()