Tyding up
This commit is contained in:
1 parent
fbe3b19aef
commit
7d6bd30e01
1 file changed
+55
-48
+55
-48
@@ -1,25 +1,26 @@
|
||||
/* Setting up the handling of Node JS process events */
|
||||
let NODE_JS_PROCESS = require('./NodeJsProcess.js');
|
||||
let NODE_JS_PROCESS_MODULE = NODE_JS_PROCESS.newNodeJsProcess()
|
||||
NODE_JS_PROCESS_MODULE.initialize()
|
||||
|
||||
/*
|
||||
We read the first string sent as an argument when the process was created by the Task Manager. There we will find the information of the identity
|
||||
of this Task and know exactly what to run within this server instance.
|
||||
*/
|
||||
let taskId = process.argv[2] // reading what comes as an argument of the nodejs process.
|
||||
|
||||
/* Setting up the global Event Handler */
|
||||
|
||||
let EVENT_SERVER_CLIENT = require('./EventServerClient.js');
|
||||
|
||||
global.EVENT_SERVER_CLIENT_MODULE = EVENT_SERVER_CLIENT.newEventsServerClient()
|
||||
global.EVENT_SERVER_CLIENT_MODULE.initialize(preLoader)
|
||||
|
||||
function preLoader() {
|
||||
/*
|
||||
We read the first string sent as an argument when the process was created by the Task Manager.
|
||||
There we will find the information of the identity
|
||||
of this Task and know exactly what to run within this server instance.
|
||||
*/
|
||||
let taskId = process.argv[2] // reading what comes as an argument of the nodejs process.
|
||||
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 */
|
||||
/*
|
||||
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 -> 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) {
|
||||
@@ -28,7 +29,7 @@ function preLoader() {
|
||||
global.TASK_NODE = JSON.parse(message.event.taskDefinition)
|
||||
global.TASK_NETWORK = JSON.parse(message.event.networkDefinition)
|
||||
global.PROJECTS_SCHEMA = JSON.parse(message.event.projectsSchema)
|
||||
bootLoader()
|
||||
bootingProcess()
|
||||
} catch (err) {
|
||||
console.log('[ERROR] Task Server -> Task -> preLoader -> eventReceived -> ' + err.stack)
|
||||
}
|
||||
@@ -42,7 +43,7 @@ function preLoader() {
|
||||
/*
|
||||
This process was started not by the Task Manager, but independently
|
||||
(most likely for debugging purposes). In this case we listen to an event
|
||||
with the Task Info that should be emitted at the UI
|
||||
with the Task Info that should be emitted at the UI, bypassing the Task Manager.
|
||||
*/
|
||||
try {
|
||||
global.EVENT_SERVER_CLIENT_MODULE.listenToEvent('Task Server', 'Debug Task Started', undefined, 'Task Server', undefined, startDebugging)
|
||||
@@ -52,7 +53,7 @@ function preLoader() {
|
||||
global.TASK_NODE = JSON.parse(message.event.taskDefinition)
|
||||
global.TASK_NETWORK = JSON.parse(message.event.networkDefinition)
|
||||
global.PROJECTS_SCHEMA = JSON.parse(message.event.projectsSchema)
|
||||
bootLoader()
|
||||
bootingProcess()
|
||||
|
||||
} catch (err) {
|
||||
console.log('[ERROR] Task Server -> Task -> preLoader -> startDebugging -> ' + err.stack)
|
||||
@@ -79,113 +80,119 @@ function preLoader() {
|
||||
}
|
||||
}
|
||||
|
||||
function bootLoader() {
|
||||
function bootingProcess() {
|
||||
|
||||
let MULTI_PROJECT = require('./MultiProject.js');
|
||||
let MULTI_PROJECT_MODULE = MULTI_PROJECT.newMultiProject()
|
||||
MULTI_PROJECT_MODULE.initialize()
|
||||
setupMultiProjectFramework()
|
||||
setupTaskHeartbeats()
|
||||
|
||||
/* Heartbeat sent to the UI */
|
||||
|
||||
let key = global.TASK_NODE.name + '-' + global.TASK_NODE.type + '-' + global.TASK_NODE.id
|
||||
|
||||
global.EVENT_SERVER_CLIENT_MODULE.createEventHandler(key)
|
||||
global.EVENT_SERVER_CLIENT_MODULE.raiseEvent(key, 'Running') // Meaning Task Running
|
||||
global.HEARTBEAT_INTERVAL_HANDLER = setInterval(taskHearBeat, 1000)
|
||||
|
||||
function taskHearBeat() {
|
||||
|
||||
/* The heartbeat event is raised at the event handler of the instance of this task, created at the TS. */
|
||||
let event = {
|
||||
seconds: (new Date()).getSeconds()
|
||||
}
|
||||
global.EVENT_SERVER_CLIENT_MODULE.raiseEvent(key, 'Heartbeat', event)
|
||||
function setupMultiProjectFramework() {
|
||||
let MULTI_PROJECT = require('./MultiProject.js');
|
||||
let MULTI_PROJECT_MODULE = MULTI_PROJECT.newMultiProject()
|
||||
MULTI_PROJECT_MODULE.initialize()
|
||||
}
|
||||
|
||||
function setupTaskHeartbeats() {
|
||||
/* Heartbeat sent to the UI */
|
||||
let key = global.TASK_NODE.name + '-' + global.TASK_NODE.type + '-' + global.TASK_NODE.id
|
||||
|
||||
global.EVENT_SERVER_CLIENT_MODULE.createEventHandler(key)
|
||||
global.EVENT_SERVER_CLIENT_MODULE.raiseEvent(key, 'Running') // Meaning Task Running
|
||||
global.HEARTBEAT_INTERVAL_HANDLER = setInterval(taskHearBeat, 1000)
|
||||
|
||||
function taskHearBeat() {
|
||||
|
||||
/* The heartbeat event is raised at the event handler of the instance of this task, created at the TS. */
|
||||
let event = {
|
||||
seconds: (new Date()).getSeconds()
|
||||
}
|
||||
global.EVENT_SERVER_CLIENT_MODULE.raiseEvent(key, 'Heartbeat', event)
|
||||
}
|
||||
}
|
||||
|
||||
for (let processIndex = 0; processIndex < global.TASK_NODE.bot.processes.length; processIndex++) {
|
||||
let config = global.TASK_NODE.bot.processes[processIndex].config
|
||||
|
||||
/* Validate that the minimun amount of input required are defined. */
|
||||
|
||||
if (global.TASK_NODE.parentNode === undefined) {
|
||||
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]));
|
||||
console.log("[ERROR] Task Server -> Task -> bootingProcess -> 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 -> Task -> 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 -> bootingProcess -> 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 -> Task -> 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 -> bootingProcess -> 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 -> Task -> 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 -> bootingProcess -> 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 -> Task -> bootLoader -> Market without a Parent. This process will not be executed. -> Process Instance = " + JSON.stringify(global.MARKET_NODE));
|
||||
console.log("[ERROR] Task Server -> Task -> bootingProcess -> 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 -> Task -> 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 -> bootingProcess -> 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 -> Task -> 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 -> bootingProcess -> 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 -> Task -> 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 -> bootingProcess -> 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 -> Task -> 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 -> bootingProcess -> 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 -> Task -> 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 -> bootingProcess -> 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 -> Task -> 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 -> bootingProcess -> 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 -> Task -> bootLoader -> Process Definition without parent Bot Definition. -> Process Definition = " + JSON.stringify(global.TASK_NODE.bot.processes[processIndex].referenceParent));
|
||||
console.log("[ERROR] Task Server -> Task -> bootingProcess -> 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 -> Task -> 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 -> bootingProcess -> 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 -> Task -> bootLoader -> Process Definition without a codeName defined. -> Process Definition = " + JSON.stringify(global.TASK_NODE.bot.processes[processIndex].referenceParent));
|
||||
console.log("[ERROR] Task Server -> Task -> bootingProcess -> 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 -> Task -> 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 -> bootingProcess -> 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 -> Task -> 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 -> bootingProcess -> Data Mine without a codeName defined. -> Data Mine Definition = " + JSON.stringify(global.TASK_NODE.bot.processes[processIndex].referenceParent.parentNode.parentNode));
|
||||
continue
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user