Merge pull request #147 from AAMasters/develop

Superalgos Beta
This commit is contained in:
Luis Fernando Molina authored and GitHub committed 2020-04-08 12:04:28 +02:00
commit 2bb1294778
13 files changed
+132 -161

No files matched your search

+69 -65
View File
@@ -1,4 +1,9 @@
exports.newSystemEventHandler = function newSystemEventHandler(ipc) {
exports.newEventsServerClient = function newEventsServerClient() {
const MODULE = "Task Server "
const ERROR_LOG = true
const INFO_LOG = false
let thisObject = {
initialize: initialize,
finalize: finalize,
@@ -12,74 +17,72 @@
let eventListeners = new Map()
let responseWaiters = new Map()
ipc.config.id = 'Task Server';
ipc.config.retry = 1500;
ipc.config.silent = true;
let WEB_SOCKETS_CLIENT
const WEB_SOCKET = require('ws')
let port = process.env.WEB_SOCKETS_SERVER_PORT
return thisObject
function initialize(canllerName, callBackFunction) {
function initialize(callBackFunction) {
ipc.connectTo(
'world',
function () {
ipc.of.world.on(
'connect',
function () {
ipc.log('## Connected to Superalgos Event Server ##'.rainbow, ipc.config.delay);
setuptWebSockets(callBackFunction)
let eventCommand = {
action: 'greetings',
from: canllerName
}
}
sendCommand(eventCommand)
function setuptWebSockets(callBackFunction) {
try {
callBackFunction()
}
);
ipc.of.world.on(
'disconnect',
function () {
ipc.log('Disconnected from Superalgos Event Server '.notice);
}
);
ipc.of.world.on(
'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)
WEB_SOCKETS_CLIENT = new WEB_SOCKET('ws://localhost:' + port )
if (message.action === 'Event Raised') {
let key
if (message.callerId) {
key = message.eventHandlerName + '-' + message.eventType + '-' + message.callerId
} else {
key = message.eventHandlerName + '-' + message.eventType
}
let handler = eventListeners.get(key)
if (handler) {
handler.callBack(message)
} else {
console.log(key + ' not found so could not deliver event raised.')
console.log(' Message = ' + data)
}
return
}
if (message.action === 'Event Server Response') {
let handler = responseWaiters.get(message.callerId)
if (handler) {
handler(message)
}
return
}
}
);
WEB_SOCKETS_CLIENT.onerror = error => {
console.log('[ERROR] Task Server -> Event Server Client -> setuptWebSockets -> On connection error -> error = ' + JSON.stringify(error))
}
);
WEB_SOCKETS_CLIENT.onopen = () => {
if (INFO_LOG === true) {
console.log('Websocket connection opened.')
}
if (callBackFunction !== undefined) {
callBackFunction()
}
}
WEB_SOCKETS_CLIENT.onmessage = e => {
try {
if (INFO_LOG === true) {
console.log('Websocket Message Received: ' + e.data)
}
let message = JSON.parse(e.data)
if (message.action === 'Event Raised') {
let key
if (message.callerId !== undefined) {
key = message.eventHandlerName + '-' + message.eventType + '-' + message.callerId
} else {
key = message.eventHandlerName + '-' + message.eventType
}
let handler = eventListeners.get(key)
if (handler) {
handler.callBack(message)
}
return
}
if (message.action === 'Event Server Response') {
let handler = responseWaiters.get(message.callerId)
if (handler) {
handler(message)
}
return
}
} catch (err) {
if (ERROR_LOG === true) { logger.write('[ERROR] Task Server -> Event Server Client -> setuptWebSockets -> onmessage -> err = ' + err.stack) }
}
}
} catch (err) {
if (ERROR_LOG === true) { logger.write('[ERROR] Task Server -> Event Server Client -> setuptWebSockets -> err = ' + err.stack) }
}
}
function finalize() {
@@ -95,7 +98,7 @@
}
sendCommand(eventCommand)
}
ipc.disconnect('world');
WEB_SOCKETS_CLIENT.close();
}
function sendCommand(command, responseCallBack, eventsCallBack) {
@@ -119,10 +122,11 @@
responseWaiters.set(command.callerId, responseCallBack)
}
ipc.of.world.emit(
'message',
JSON.stringify(command)
)
if (WEB_SOCKETS_CLIENT.readyState === 1) { // 1 means connected and ready.
WEB_SOCKETS_CLIENT.send("Task Server" + "|*|" + "|*|" + JSON.stringify(command))
} else {
console.log('[ERROR] Task Server -> Event Server Client -> setuptWebSockets -> sendCommand -> WebSocket message could not be sent because the connection was not ready. Message = ' + JSON.stringify(command))
}
}
function createEventHandler(eventHandlerName, callerId, responseCallBack) {
+2 -2
View File
@@ -1088,11 +1088,11 @@
percentage: percentage,
status: status
}
global.SYSTEM_EVENT_HANDLER.raiseEvent(bot.processKey, 'Heartbeat', event)
global.EVENT_SERVER_CLIENT.raiseEvent(bot.processKey, 'Heartbeat', event)
}
function processStopped() {
global.SYSTEM_EVENT_HANDLER.raiseEvent(bot.processKey, 'Stopped')
global.EVENT_SERVER_CLIENT.raiseEvent(bot.processKey, 'Stopped')
}
} catch (err) {
+1 -1
View File
@@ -1009,7 +1009,7 @@
dateRange: dataRange
}
global.SYSTEM_EVENT_HANDLER.raiseEvent(key, 'Data Range Updated', event)
global.EVENT_SERVER_CLIENT.raiseEvent(key, 'Data Range Updated', event)
callBack(global.DEFAULT_OK_RESPONSE);
}
+1 -1
View File
@@ -787,7 +787,7 @@
dateRange: dataRange
}
global.SYSTEM_EVENT_HANDLER.raiseEvent(key, 'Data Range Updated', event)
global.EVENT_SERVER_CLIENT.raiseEvent(key, 'Data Range Updated', event)
callBack(global.DEFAULT_OK_RESPONSE);
}
+8 -8
View File
@@ -81,7 +81,7 @@
if (global.LOG_CONTROL[MODULE_NAME].logInfo === true) { logger.write(MODULE_NAME, "[INFO] start -> waitForDependantProcess -> key = " + key); }
if (global.LOG_CONTROL[MODULE_NAME].logInfo === true) { logger.write(MODULE_NAME, "[INFO] start -> waitForDependantProcess -> callerId = " + callerId); }
global.SYSTEM_EVENT_HANDLER.listenToEvent(key, 'Process Execution Finished', undefined, callerId, responseCallBack, eventsCallBack)
global.EVENT_SERVER_CLIENT.listenToEvent(key, 'Process Execution Finished', undefined, callerId, responseCallBack, eventsCallBack)
bot.processHeartBeat(undefined, undefined, "Waiting for " + processThisDependsOn.parentNode.parentNode.name + "->" + processThisDependsOn.parentNode.code.codeName + "->" + processThisDependsOn.code.codeName)
@@ -102,15 +102,15 @@
/* We continue the normal flow after we learn the dependent process has finished its execution. */
if (global.LOG_CONTROL[MODULE_NAME].logInfo === true) { logger.write(MODULE_NAME, "[INFO] start -> eventsCallBack -> stopListening to Process Execution Finished. "); }
if (global.LOG_CONTROL[MODULE_NAME].logInfo === true) { logger.write(MODULE_NAME, "[INFO] start -> eventsCallBack -> subscriptionId = " + subscriptionId); }
global.SYSTEM_EVENT_HANDLER.stopListening(key, 'Process Execution Finished', subscriptionId)
global.EVENT_SERVER_CLIENT.stopListening(key, 'Process Execution Finished', subscriptionId)
if (message.event.err.result === global.DEFAULT_OK_RESPONSE.result) {
/* We emit our own event that the process started. */
let event = {
err: global.DEFAULT_OK_RESPONSE
}
global.SYSTEM_EVENT_HANDLER.createEventHandler(currentProcessKey, 'Process Execution Started')
global.SYSTEM_EVENT_HANDLER.raiseEvent(currentProcessKey, 'Process Execution Started', event)
global.EVENT_SERVER_CLIENT.createEventHandler(currentProcessKey, 'Process Execution Started')
global.EVENT_SERVER_CLIENT.raiseEvent(currentProcessKey, 'Process Execution Started', event)
bot.processHeartBeat(undefined, undefined,"Running...")
@@ -125,8 +125,8 @@
let event = {
err: global.DEFAULT_OK_RESPONSE
}
global.SYSTEM_EVENT_HANDLER.createEventHandler(currentProcessKey, 'Process Execution Started')
global.SYSTEM_EVENT_HANDLER.raiseEvent(currentProcessKey, 'Process Execution Started', event)
global.EVENT_SERVER_CLIENT.createEventHandler(currentProcessKey, 'Process Execution Started')
global.EVENT_SERVER_CLIENT.raiseEvent(currentProcessKey, 'Process Execution Started', event)
if (global.LOG_CONTROL[MODULE_NAME].logInfo === true) { logger.write(MODULE_NAME, "[INFO] start -> " + currentProcessKey + " Process Execution Started " ); }
@@ -149,8 +149,8 @@
err: global.DEFAULT_OK_RESPONSE
}
global.SYSTEM_EVENT_HANDLER.createEventHandler(currentProcessKey, 'Process Execution Finished')
global.SYSTEM_EVENT_HANDLER.raiseEvent(currentProcessKey, 'Process Execution Finished', event)
global.EVENT_SERVER_CLIENT.createEventHandler(currentProcessKey, 'Process Execution Finished')
global.EVENT_SERVER_CLIENT.raiseEvent(currentProcessKey, 'Process Execution Finished', event)
if (global.LOG_CONTROL[MODULE_NAME].logInfo === true) { logger.write(MODULE_NAME, "[INFO] finish -> " + currentProcessKey + " Process Execution Finished " ); }
+2 -2
View File
@@ -85,8 +85,8 @@
let event = {
lastFile: lastFile
}
global.SYSTEM_EVENT_HANDLER.createEventHandler(key, 'Dataset Updated')
global.SYSTEM_EVENT_HANDLER.raiseEvent(key, 'Dataset Updated', event)
global.EVENT_SERVER_CLIENT.createEventHandler(key, 'Dataset Updated')
global.EVENT_SERVER_CLIENT.raiseEvent(key, 'Dataset Updated', event)
}
}
+1
View File
@@ -51,6 +51,7 @@
<Compile Include="Session.js">
<SubType>Code</SubType>
</Compile>
<Compile Include="EventServerClient.js" />
<Compile Include="TradingBot.js">
<SubType>Code</SubType>
</Compile>
+2 -2
View File
@@ -810,11 +810,11 @@
percentage: percentage,
status: status
}
global.SYSTEM_EVENT_HANDLER.raiseEvent(bot.processKey, 'Heartbeat', event)
global.EVENT_SERVER_CLIENT.raiseEvent(bot.processKey, 'Heartbeat', event)
}
function processStopped() {
global.SYSTEM_EVENT_HANDLER.raiseEvent(bot.processKey, 'Stopped')
global.EVENT_SERVER_CLIENT.raiseEvent(bot.processKey, 'Stopped')
}
}
+2 -2
View File
@@ -38,8 +38,8 @@
/* Listen to event to start or stop the session. */
bot.sessionKey = bot.processNode.session.name + '-' + bot.processNode.session.type + '-' + bot.processNode.session.id
global.SYSTEM_EVENT_HANDLER.listenToEvent(bot.sessionKey, 'Run Session', undefined, undefined, undefined, runSession)
global.SYSTEM_EVENT_HANDLER.listenToEvent(bot.sessionKey, 'Stop Session', undefined, undefined, undefined, stopSession)
global.EVENT_SERVER_CLIENT.listenToEvent(bot.sessionKey, 'Run Session', undefined, bot.sessionKey, undefined, runSession)
global.EVENT_SERVER_CLIENT.listenToEvent(bot.sessionKey, 'Stop Session', undefined, bot.sessionKey, undefined, stopSession)
callBackFunction(global.DEFAULT_OK_RESPONSE)
return
+7 -7
View File
@@ -164,12 +164,12 @@
/* Checking if we need to need to emit any event */
if (bot.SESSION_STATUS === 'Idle' && bot.STOP_SESSION === false) {
global.SYSTEM_EVENT_HANDLER.raiseEvent(bot.sessionKey, 'Running')
global.EVENT_SERVER_CLIENT.raiseEvent(bot.sessionKey, 'Running')
bot.SESSION_STATUS = 'Running'
}
if (bot.SESSION_STATUS === 'Running' && bot.STOP_SESSION === true) {
global.SYSTEM_EVENT_HANDLER.raiseEvent(bot.sessionKey, 'Stopped')
global.EVENT_SERVER_CLIENT.raiseEvent(bot.sessionKey, 'Stopped')
bot.SESSION_STATUS = 'Stopped'
}
@@ -880,7 +880,7 @@
logger.persist();
}
global.SYSTEM_EVENT_HANDLER.raiseEvent(bot.sessionKey, 'Stopped')
global.EVENT_SERVER_CLIENT.raiseEvent(bot.sessionKey, 'Stopped')
processStopped()
callBackFunction(global.DEFAULT_OK_RESPONSE);
return;
@@ -1013,7 +1013,7 @@
percentage: percentage,
status: status
}
global.SYSTEM_EVENT_HANDLER.raiseEvent(bot.processKey, 'Heartbeat', event)
global.EVENT_SERVER_CLIENT.raiseEvent(bot.processKey, 'Heartbeat', event)
}
function sessionHeartBeat(processingDate) {
@@ -1021,7 +1021,7 @@
seconds: (new Date()).getSeconds(),
processingDate: processingDate
}
global.SYSTEM_EVENT_HANDLER.raiseEvent(bot.sessionKey, 'Heartbeat', event)
global.EVENT_SERVER_CLIENT.raiseEvent(bot.sessionKey, 'Heartbeat', event)
if (global.STOP_TASK_GRACEFULLY === true) {
bot.STOP_SESSION = true
@@ -1029,12 +1029,12 @@
}
function processStopped() {
global.SYSTEM_EVENT_HANDLER.raiseEvent(bot.processKey, 'Stopped')
global.EVENT_SERVER_CLIENT.raiseEvent(bot.processKey, 'Stopped')
}
function sessionStopped() {
if (bot.SESSION_STATUS === 'Running') {
global.SYSTEM_EVENT_HANDLER.raiseEvent(bot.sessionKey, 'Stopped')
global.EVENT_SERVER_CLIENT.raiseEvent(bot.sessionKey, 'Stopped')
bot.SESSION_STATUS = 'Stopped'
}
}
+15 -49
View File
@@ -4,15 +4,10 @@
"lockfileVersion": 1,
"requires": true,
"dependencies": {
"@types/node": {
"version": "13.7.0",
"resolved": "https://registry.npmjs.org/@types/node/-/node-13.7.0.tgz",
"integrity": "sha512-GnZbirvmqZUzMgkFn70c74OQpTTUcCzlhQliTzYjQMqg+hVKcDnxdL19Ne3UdYzdMA/+W3eb646FWn/ZaT1NfQ=="
},
"ccxt": {
"version": "1.22.39",
"resolved": "https://registry.npmjs.org/ccxt/-/ccxt-1.22.39.tgz",
"integrity": "sha512-Vq4BzYS/FwRudPKQ6BQGU3SVntYv7EAQGT+2guf+e7qm45CJMhdoVwR1z89kl42fbK39XMnl8sUnRCwsKPs38A=="
"version": "1.25.80",
"resolved": "https://registry.npmjs.org/ccxt/-/ccxt-1.25.80.tgz",
"integrity": "sha512-AUWagxMa8PMexRabbktWezlmVacj6L2Ep4844ebIXUOyME2Ommg7O/9/pq0F2Ne1IHcJnNJzHrMYQvkh2gBtlw=="
},
"debug": {
"version": "4.1.1",
@@ -27,33 +22,10 @@
"resolved": "https://registry.npmjs.org/dotenv/-/dotenv-8.2.0.tgz",
"integrity": "sha512-8sJ78ElpbDJBHNeBzUbUVLsqKdccaa/BXF1uPTw3GrvQTBgrQrtObr2mUrE38vzYd8cEv+m/JBfDLioYcfXoaw=="
},
"easy-stack": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/easy-stack/-/easy-stack-1.0.0.tgz",
"integrity": "sha1-EskbMIWjfwuqM26UhurEv5Tj54g="
},
"event-pubsub": {
"version": "4.3.0",
"resolved": "https://registry.npmjs.org/event-pubsub/-/event-pubsub-4.3.0.tgz",
"integrity": "sha512-z7IyloorXvKbFx9Bpie2+vMJKKx1fH1EN5yiTfp8CiLOTptSYy1g8H4yDpGlEdshL1PBiFtBHepF2cNsqeEeFQ=="
},
"js-message": {
"version": "1.0.5",
"resolved": "https://registry.npmjs.org/js-message/-/js-message-1.0.5.tgz",
"integrity": "sha1-IwDSSxrwjondCVvBpMnJz8uJLRU="
},
"js-queue": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/js-queue/-/js-queue-2.0.0.tgz",
"integrity": "sha1-NiITz4YPRo8BJfxslqvBdCUx+Ug=",
"requires": {
"easy-stack": "1.0.0"
}
},
"minimist": {
"version": "1.2.0",
"resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.0.tgz",
"integrity": "sha1-o1AIsg9BOD7sH7kU9M1d95omQoQ="
"version": "1.2.5",
"resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.5.tgz",
"integrity": "sha512-FM9nNUYrRBAELZQT3xeZQ7fmMOBg6nWNmJKTcgsJeaLstP/UODVpGsr5OhXhhXg6f+qtJ8uiZ+PUxkDWcgIXLw=="
},
"module-alias": {
"version": "2.2.2",
@@ -70,29 +42,18 @@
"resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.0.tgz",
"integrity": "sha512-8dG4H5ujfvFiqDmVu9fQ5bOHUC15JMjMY/Zumv26oOvvVJjM67KF8koCWIabKQ1GJIa9r2mMZscBq/TbdOcmNA=="
},
"node-ipc": {
"version": "9.1.1",
"resolved": "https://registry.npmjs.org/node-ipc/-/node-ipc-9.1.1.tgz",
"integrity": "sha512-FAyICv0sIRJxVp3GW5fzgaf9jwwRQxAKDJlmNFUL5hOy+W4X/I5AypyHoq0DXXbo9o/gt79gj++4cMr4jVWE/w==",
"requires": {
"event-pubsub": "4.3.0",
"js-message": "1.0.5",
"js-queue": "2.0.0"
}
},
"sandwich-stream": {
"version": "2.0.2",
"resolved": "https://registry.npmjs.org/sandwich-stream/-/sandwich-stream-2.0.2.tgz",
"integrity": "sha512-jLYV0DORrzY3xaz/S9ydJL6Iz7essZeAfnAavsJ+zsJGZ1MOnsS52yRjU3uF3pJa/lla7+wisp//fxOwOH8SKQ=="
},
"telegraf": {
"version": "3.36.0",
"resolved": "https://registry.npmjs.org/telegraf/-/telegraf-3.36.0.tgz",
"integrity": "sha512-9o6AJKRiTm5vMWYI6WpTfBHzu4FMpWBNKxvnMxRds/cbMY9RnsVVjdi8i4bFFlfd+xbi73EbrnI3dybayryICA==",
"version": "3.37.0",
"resolved": "https://registry.npmjs.org/telegraf/-/telegraf-3.37.0.tgz",
"integrity": "sha512-V3448qwfOolBqkIc87yxjW4zMvR2P6AIF24pPTlX9WhZPwA1TF/x3nQhnWPRLtGh2SJuvDcr83iTkXPXT7Opnw==",
"requires": {
"@types/node": "13.7.0",
"debug": "4.1.1",
"minimist": "1.2.0",
"minimist": "1.2.5",
"module-alias": "2.2.2",
"node-fetch": "2.6.0",
"sandwich-stream": "2.0.2",
@@ -103,6 +64,11 @@
"version": "3.6.1",
"resolved": "https://registry.npmjs.org/telegram-typings/-/telegram-typings-3.6.1.tgz",
"integrity": "sha512-njVv1EAhIZnmQVLocZEADYUyqA1WIXuVcDYlsp+mXua/XB0pxx+PKtMSPeZ/EE4wPWTw9h/hA9ASTT6yQelkiw=="
},
"ws": {
"version": "7.2.3",
"resolved": "https://registry.npmjs.org/ws/-/ws-7.2.3.tgz",
"integrity": "sha512-HTDl9G9hbkNDk98naoR/cHDws7+EyYMOdL1BmjsZXRUjf7d+MficC4B7HLUPlSiho0vg+CWKrGIt/VJBd1xunQ=="
}
}
}
+3 -3
View File
@@ -13,9 +13,9 @@
"test": "echo \"Error: no test specified\" && exit 1"
},
"dependencies": {
"ccxt": "^1.22.39",
"ccxt": "^1.25.80",
"dotenv": "^8.2.0",
"node-ipc": "^9.1.1",
"telegraf": "^3.36.0"
"telegraf": "^3.37.0",
"ws": "^7.1.2"
}
}
+19 -19
View File
@@ -27,8 +27,6 @@ global.CUSTOM_FAIL_RESPONSE = {
const ONE_DAY_IN_MILISECONDS = 24 * 60 * 60 * 1000;
/* Process Events */
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)
@@ -42,14 +40,15 @@ 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, 'Stopped') // Meaning Task Stopped
global.SYSTEM_EVENT_HANDLER.deleteEventHandler(key)
global.SYSTEM_EVENT_HANDLER.finalize()
global.SYSTEM_EVENT_HANDLER = undefined
if (global.TASK_NODE !== undefined) {
/* 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.EVENT_SERVER_CLIENT.raiseEvent(key, 'Stopped') // Meaning Task Stopped
global.EVENT_SERVER_CLIENT.finalize()
global.EVENT_SERVER_CLIENT = undefined
}
//console.log('[INFO] Task Server -> server -> process.on.exit -> About to exit -> code = ' + code)
})
@@ -80,7 +79,7 @@ global.EXIT_NODE_PROCESS = function exitProcess() {
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
global.EVENT_SERVER_CLIENT.raiseEvent(key, 'Stopped') // Meaning Process Stopped
}
//console.log("[INFO] Task Server -> " + global.TASK_NODE.name + " -> EXIT_NODE_PROCESS -> Task Server will stop in 10 seconds.");
@@ -111,10 +110,10 @@ let taskId = process.argv[2] // reading what comes as an argument of the nodejs
/* Setting up the global Event Handler */
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', preLoader)
let EVENT_SERVER_CLIENT = require('./EventServerClient.js');
global.EVENT_SERVER_CLIENT = EVENT_SERVER_CLIENT.newEventsServerClient()
global.EVENT_SERVER_CLIENT.initialize(preLoader)
global.STOP_TASK_GRACEFULLY = false;
function preLoader() {
@@ -122,7 +121,8 @@ function preLoader() {
/* 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)
global.SYSTEM_EVENT_HANDLER.listenToEvent('Task Server - ' + taskId, 'Run Task', undefined, undefined, undefined, eventReceived)
global.EVENT_SERVER_CLIENT.listenToEvent('Task Server - ' + taskId, 'Run Task', undefined, 'Task Server - ' + taskId, undefined, eventReceived)
global.EVENT_SERVER_CLIENT.raiseEvent('Task Manager - ' + taskId, 'Nodejs Process Ready for Task')
function eventReceived(message) {
global.TASK_NODE = message
global.TASK_NODE = JSON.parse(message.event.definition)
@@ -136,7 +136,7 @@ function preLoader() {
else { /* 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 */
try {
//console.log('[INFO] Task Server -> server -> preLoader -> Waiting for event to start debugging...')
global.SYSTEM_EVENT_HANDLER.listenToEvent('Task Server', 'Debug Task Started', undefined, undefined, undefined, startDebugging)
global.EVENT_SERVER_CLIENT.listenToEvent('Task Server', 'Debug Task Started', undefined, 'Task Server', undefined, startDebugging)
function startDebugging(message) {
global.TASK_NODE = message
global.TASK_NODE = JSON.parse(message.event.definition)
@@ -155,8 +155,8 @@ 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, 'Running') // Meaning Task Running
global.EVENT_SERVER_CLIENT.createEventHandler(key)
global.EVENT_SERVER_CLIENT.raiseEvent(key, 'Running') // Meaning Task Running
global.HEARTBEAT_INTERVAL_HANDLER = setInterval(taskHearBeat, 1000)
function taskHearBeat() {
@@ -165,7 +165,7 @@ function bootLoader() {
let event = {
seconds: (new Date()).getSeconds()
}
global.SYSTEM_EVENT_HANDLER.raiseEvent(key, 'Heartbeat', event)
global.EVENT_SERVER_CLIENT.raiseEvent(key, 'Heartbeat', event)
}
for (let processIndex = 0; processIndex < global.TASK_NODE.bot.processes.length; processIndex++) {