Session and Task Syncronization with the backend
This commit is contained in:
1 parent
1c2a335f6f
commit
ec4450f0fe
10 files changed
+115
-75
No files matched your search
@@ -146,6 +146,8 @@
|
||||
} else {
|
||||
/* We are processing Daily Files */
|
||||
do {
|
||||
global.EMIT_SESSION_STATUS (bot.SESSION_STATUS, bot.sessionKey)
|
||||
|
||||
if (checkStopTaskGracefully() === false) { break }
|
||||
if (checkStopProcessing() === false) { break }
|
||||
|
||||
@@ -401,7 +403,7 @@
|
||||
async function processDailyFiles() {
|
||||
/* Telling the world we are alive and doing well and which date we are processing right now. */
|
||||
let processingDateString = tradingProcessDate.getUTCFullYear() + '-' + utilities.pad(tradingProcessDate.getUTCMonth() + 1, 2) + '-' + utilities.pad(tradingProcessDate.getUTCDate(), 2);
|
||||
bot.processHeartBeat(processingDateString)
|
||||
bot.processHeartBeat(processingDateString, undefined, "Running...")
|
||||
|
||||
/*
|
||||
We will iterate through all posible timeFrames.
|
||||
|
||||
+22
-7
@@ -38,8 +38,9 @@
|
||||
bot.sessionKey = bot.processNode.session.name + '-' + bot.processNode.session.type + '-' + bot.processNode.session.id
|
||||
global.SESSION_MAP.set(bot.sessionKey, bot.sessionKey)
|
||||
|
||||
global.EVENT_SERVER_CLIENT.listenToEvent(bot.sessionKey, 'Run Session', undefined, bot.sessionKey, undefined, onSessionRan)
|
||||
global.EVENT_SERVER_CLIENT.listenToEvent(bot.sessionKey, 'Stop Session', undefined, bot.sessionKey, undefined, onSessionStopped)
|
||||
global.EVENT_SERVER_CLIENT.listenToEvent(bot.sessionKey, 'Session Status', undefined, bot.sessionKey, undefined, onSessionStatus)
|
||||
global.EVENT_SERVER_CLIENT.listenToEvent(bot.sessionKey, 'Run Session', undefined, bot.sessionKey, undefined, onSessionRun)
|
||||
global.EVENT_SERVER_CLIENT.listenToEvent(bot.sessionKey, 'Stop Session', undefined, bot.sessionKey, undefined, onSessionStop)
|
||||
|
||||
/* Connect this here so that it is accesible from other places */
|
||||
bot.sessionError = sessionError
|
||||
@@ -52,11 +53,25 @@
|
||||
callBackFunction(global.DEFAULT_OK_RESPONSE)
|
||||
return
|
||||
|
||||
function onSessionRan(message) {
|
||||
function onSessionStatus() {
|
||||
if (bot.SESSION_STATUS === 'Running') {
|
||||
let event = {
|
||||
status: 'Session Runnning'
|
||||
}
|
||||
global.EVENT_SERVER_CLIENT.raiseEvent(bot.sessionKey, 'Status Response', event)
|
||||
} else {
|
||||
let event = {
|
||||
status: 'Not Session Runnning'
|
||||
}
|
||||
global.EVENT_SERVER_CLIENT.raiseEvent(bot.sessionKey, 'Status Response', event)
|
||||
}
|
||||
}
|
||||
|
||||
function onSessionRun(message) {
|
||||
try {
|
||||
/* This happens when the UI is reloaded, the session was running and tries to run it again. */
|
||||
if (bot.SESSION_STATUS === 'Idle' || bot.SESSION_STATUS === 'Running') {
|
||||
parentLogger.write(MODULE_NAME, "[WARN] onSessionRan -> Event receive to run the Session while it was already running. ")
|
||||
parentLogger.write(MODULE_NAME, "[WARN] onSessionRun -> Event receive to run the Session while it was already running. ")
|
||||
return
|
||||
}
|
||||
|
||||
@@ -100,16 +115,16 @@
|
||||
bot.STOP_SESSION = false
|
||||
} else {
|
||||
bot.STOP_SESSION = true
|
||||
if (FULL_LOG === true) { parentLogger.write(MODULE_NAME, '[IMPORTANT] onSessionRan -> Stopping the Session now. ') }
|
||||
if (FULL_LOG === true) { parentLogger.write(MODULE_NAME, '[IMPORTANT] onSessionRun -> Stopping the Session now. ') }
|
||||
}
|
||||
|
||||
socialBotsModule.sendMessage(bot.SESSION.type + " '" + bot.SESSION.name + "' is starting.")
|
||||
} catch (err) {
|
||||
parentLogger.write(MODULE_NAME, "[ERROR] initialize -> onSessionRan -> err = " + err.stack);
|
||||
parentLogger.write(MODULE_NAME, "[ERROR] initialize -> onSessionRun -> err = " + err.stack);
|
||||
}
|
||||
}
|
||||
|
||||
function onSessionStopped() {
|
||||
function onSessionStop() {
|
||||
stopSession('Session Stopped From the User Interface.')
|
||||
}
|
||||
|
||||
|
||||
@@ -74,7 +74,7 @@
|
||||
let nextWaitTime;
|
||||
|
||||
/* We tell the UI that we are running. */
|
||||
processHeartBeat()
|
||||
processHeartBeat(undefined, undefined, "Running...")
|
||||
|
||||
/* We define here all the modules that the rest of the infraestructure, including the bots themselves can consume. */
|
||||
const UTILITIES = require(global.ROOT_DIR + 'CloudUtilities');
|
||||
@@ -94,14 +94,14 @@
|
||||
|
||||
/* Checking if we need to need to emit any event */
|
||||
if (bot.SESSION_STATUS === 'Idle' && bot.STOP_SESSION === false) {
|
||||
global.EVENT_SERVER_CLIENT.raiseEvent(bot.sessionKey, 'Running')
|
||||
bot.SESSION_STATUS = 'Running'
|
||||
}
|
||||
|
||||
if (bot.SESSION_STATUS === 'Running' && bot.STOP_SESSION === true) {
|
||||
global.EVENT_SERVER_CLIENT.raiseEvent(bot.sessionKey, 'Stopped')
|
||||
bot.SESSION_STATUS = 'Stopped'
|
||||
}
|
||||
}
|
||||
|
||||
global.EMIT_SESSION_STATUS (bot.SESSION_STATUS, bot.sessionKey)
|
||||
|
||||
/* Checking if we should process this loop or not.*/
|
||||
if (bot.STOP_SESSION === true) {
|
||||
@@ -523,7 +523,7 @@
|
||||
if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] run -> loop -> loopControl -> nextWaitTime = " + nextWaitTime); }
|
||||
|
||||
/* We show we reached the end of the loop. */
|
||||
processHeartBeat()
|
||||
processHeartBeat(undefined, undefined, "Running...")
|
||||
|
||||
/* Here we check if we must stop the loop gracefully. */
|
||||
shallWeStop(onStop, onContinue);
|
||||
|
||||
@@ -285,6 +285,18 @@ global.FILTER_OUT_NODES_WITHOUT_REFERENCE_PARENT_FROM_NODE_ARRAY = function (nod
|
||||
return filteredNodeArray
|
||||
}
|
||||
|
||||
global.EMIT_SESSION_STATUS = function (status, key) {
|
||||
switch(status) {
|
||||
case 'Running': {
|
||||
global.EVENT_SERVER_CLIENT.raiseEvent(key, 'Running')
|
||||
break
|
||||
}
|
||||
case 'Stopped': {
|
||||
global.EVENT_SERVER_CLIENT.raiseEvent(key, 'Stopped')
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
process.on('uncaughtException', function (err) {
|
||||
console.log('[ERROR] Task Server -> server -> uncaughtException -> err.message = ' + err.message)
|
||||
|
||||
Reference in new issue
Block a user