diff --git a/Projects/ProjectsSchema.json b/Projects/ProjectsSchema.json index e00cc7721..f5903a992 100644 --- a/Projects/ProjectsSchema.json +++ b/Projects/ProjectsSchema.json @@ -350,6 +350,12 @@ "functionName": "newSuperalgosGlobalsProcessVariables", "fileName": "ProcessVariables.js" }, + { + "name": "Task Variables", + "propertyName": "taskVariables", + "functionName": "newSuperalgosGlobalsTaskVariables", + "fileName": "TaskVariables.js" + }, { "name": "NODE JS Constants", "propertyName": "nodeJSConstants", diff --git a/Projects/Superalgos/Bots-Plotters-Code/Masters/bots/Exchange-Raw-Data-Sensor-Bot/Historic-OHLCVs/User.Bot.js b/Projects/Superalgos/Bots-Plotters-Code/Masters/bots/Exchange-Raw-Data-Sensor-Bot/Historic-OHLCVs/User.Bot.js index 02e8317ee..3aedb4622 100644 --- a/Projects/Superalgos/Bots-Plotters-Code/Masters/bots/Exchange-Raw-Data-Sensor-Bot/Historic-OHLCVs/User.Bot.js +++ b/Projects/Superalgos/Bots-Plotters-Code/Masters/bots/Exchange-Raw-Data-Sensor-Bot/Historic-OHLCVs/User.Bot.js @@ -134,7 +134,7 @@ exports.newUserBot = function newUserBot(bot, logger, COMMONS, UTILITIES, FILE_S function start(callBackFunction) { try { - if (global.STOP_TASK_GRACEFULLY === true) { + if (TS.projects.superalgos.globals.taskVariables.IS_TASK_STOPPING === true) { callBackFunction(TS.projects.superalgos.globals.standardResponses.DEFAULT_OK_RESPONSE); return } @@ -149,7 +149,7 @@ exports.newUserBot = function newUserBot(bot, logger, COMMONS, UTILITIES, FILE_S await getFirstId() await getOHLCVs() if (abort === true) { return } - if (global.STOP_TASK_GRACEFULLY === true) { + if (TS.projects.superalgos.globals.taskVariables.IS_TASK_STOPPING === true) { callBackFunction(TS.projects.superalgos.globals.standardResponses.DEFAULT_OK_RESPONSE); return } @@ -347,7 +347,7 @@ exports.newUserBot = function newUserBot(bot, logger, COMMONS, UTILITIES, FILE_S if ( OHLCVs.length < limit - 1 || - global.STOP_TASK_GRACEFULLY === true || + TS.projects.superalgos.globals.taskVariables.IS_TASK_STOPPING === true || allOHLCVs.length >= MAX_OHLCVs_PER_EXECUTION ) { break @@ -603,7 +603,7 @@ exports.newUserBot = function newUserBot(bot, logger, COMMONS, UTILITIES, FILE_S } function controlLoop() { - if (global.STOP_TASK_GRACEFULLY === true) { + if (TS.projects.superalgos.globals.taskVariables.IS_TASK_STOPPING === true) { callBackFunction(TS.projects.superalgos.globals.standardResponses.DEFAULT_OK_RESPONSE); return } diff --git a/Projects/Superalgos/Bots-Plotters-Code/Masters/bots/Exchange-Raw-Data-Sensor-Bot/Historic-Trades/User.Bot.js b/Projects/Superalgos/Bots-Plotters-Code/Masters/bots/Exchange-Raw-Data-Sensor-Bot/Historic-Trades/User.Bot.js index 30e80e937..c8b33628b 100644 --- a/Projects/Superalgos/Bots-Plotters-Code/Masters/bots/Exchange-Raw-Data-Sensor-Bot/Historic-Trades/User.Bot.js +++ b/Projects/Superalgos/Bots-Plotters-Code/Masters/bots/Exchange-Raw-Data-Sensor-Bot/Historic-Trades/User.Bot.js @@ -109,7 +109,7 @@ exports.newUserBot = function newUserBot(bot, logger, COMMONS, UTILITIES, FILE_S function start(callBackFunction) { try { - if (global.STOP_TASK_GRACEFULLY === true) { + if (TS.projects.superalgos.globals.taskVariables.IS_TASK_STOPPING === true) { callBackFunction(TS.projects.superalgos.globals.standardResponses.DEFAULT_OK_RESPONSE); return } @@ -124,7 +124,7 @@ exports.newUserBot = function newUserBot(bot, logger, COMMONS, UTILITIES, FILE_S await getFirstId() await getTrades() if (abort === true) { return} - if (global.STOP_TASK_GRACEFULLY === true) { + if (TS.projects.superalgos.globals.taskVariables.IS_TASK_STOPPING === true) { callBackFunction(TS.projects.superalgos.globals.standardResponses.DEFAULT_OK_RESPONSE); return } @@ -270,7 +270,7 @@ exports.newUserBot = function newUserBot(bot, logger, COMMONS, UTILITIES, FILE_S if ( trades.length < limit - 1 || - global.STOP_TASK_GRACEFULLY === true || + TS.projects.superalgos.globals.taskVariables.IS_TASK_STOPPING === true || allTrades.length >= MAX_TRADES_PER_EXECUTION ) { break @@ -431,7 +431,7 @@ exports.newUserBot = function newUserBot(bot, logger, COMMONS, UTILITIES, FILE_S } function controlLoop() { - if (global.STOP_TASK_GRACEFULLY === true) { + if (TS.projects.superalgos.globals.taskVariables.IS_TASK_STOPPING === true) { callBackFunction(TS.projects.superalgos.globals.standardResponses.DEFAULT_OK_RESPONSE); return } diff --git a/Projects/Superalgos/Bots-Plotters-Code/Masters/bots/Webhooks-Sensor-Bot/Check-Webhook/User.Bot.js b/Projects/Superalgos/Bots-Plotters-Code/Masters/bots/Webhooks-Sensor-Bot/Check-Webhook/User.Bot.js index e1c1ed379..3044340c0 100644 --- a/Projects/Superalgos/Bots-Plotters-Code/Masters/bots/Webhooks-Sensor-Bot/Check-Webhook/User.Bot.js +++ b/Projects/Superalgos/Bots-Plotters-Code/Masters/bots/Webhooks-Sensor-Bot/Check-Webhook/User.Bot.js @@ -36,7 +36,7 @@ exports.newUserBot = function newUserBot(bot, logger, COMMONS, UTILITIES, FILE_S function start(callBackFunction) { try { - if (global.STOP_TASK_GRACEFULLY === true) { + if (TS.projects.superalgos.globals.taskVariables.IS_TASK_STOPPING === true) { callBackFunction(TS.projects.superalgos.globals.standardResponses.DEFAULT_OK_RESPONSE); return } diff --git a/Projects/Superalgos/TS/Globals/TaskVariables.js b/Projects/Superalgos/TS/Globals/TaskVariables.js new file mode 100644 index 000000000..0eb89594c --- /dev/null +++ b/Projects/Superalgos/TS/Globals/TaskVariables.js @@ -0,0 +1,11 @@ +exports.newSuperalgosGlobalsTaskVariables = function () { + /* + Since the moment the task is stopped by the UI untiil the time the task can be stopped gracefully, + we turn on this switch that will signal every internal procedure that it must stop. + */ + let thisObject = { + IS_TASK_STOPPING: false + } + + return thisObject +} \ No newline at end of file diff --git a/TaskServer/Globals.js b/TaskServer/Globals.js index 4b01021ee..bcc96280f 100644 --- a/TaskServer/Globals.js +++ b/TaskServer/Globals.js @@ -11,6 +11,5 @@ exports.newGlobals = function () { global.LOGGER_MAP = new Map() // We will put all the loggers in a map, so that we can eventually finalize them. global.SESSION_MAP = new Map() // We will put all the sessions in a map, so that we can eventually finalize them. - global.STOP_TASK_GRACEFULLY = false; } } \ No newline at end of file diff --git a/TaskServer/IndicatorBot.js b/TaskServer/IndicatorBot.js index 5492824b3..5dd9ef03b 100644 --- a/TaskServer/IndicatorBot.js +++ b/TaskServer/IndicatorBot.js @@ -202,7 +202,7 @@ case TS.projects.superalgos.globals.standardResponses.DEFAULT_OK_RESPONSE.result: { logger.write(MODULE_NAME, "[INFO] run -> loop -> startProcessExecutionEvents -> onStarted -> Execution finished well."); - if (global.STOP_TASK_GRACEFULLY === true) { + if (TS.projects.superalgos.globals.taskVariables.IS_TASK_STOPPING === true) { loopControl() return } @@ -733,7 +733,7 @@ function shallWeStop(stopCallBack, continueCallBack) { try { /* IMPORTANT: This function is exactly the same on the 3 modules. */ - if (!global.STOP_TASK_GRACEFULLY) { + if (!TS.projects.superalgos.globals.taskVariables.IS_TASK_STOPPING) { continueCallBack(); } else { stopCallBack(); diff --git a/TaskServer/LearningSession.js b/TaskServer/LearningSession.js index 9189cbf98..85d9754f1 100644 --- a/TaskServer/LearningSession.js +++ b/TaskServer/LearningSession.js @@ -438,7 +438,7 @@ exports.newLearningSession = function newLearningSession(bot, parentLogger) { } global.EVENT_SERVER_CLIENT_MODULE.raiseEvent(bot.sessionKey, 'Heartbeat', event) - if (global.STOP_TASK_GRACEFULLY === true) { + if (TS.projects.superalgos.globals.taskVariables.IS_TASK_STOPPING === true) { bot.STOP_SESSION = true parentLogger.write(MODULE_NAME, '[IMPORTANT] sessionHeartBeat -> Stopping the Session now. ') } @@ -460,7 +460,7 @@ exports.newLearningSession = function newLearningSession(bot, parentLogger) { } global.EVENT_SERVER_CLIENT_MODULE.raiseEvent(bot.sessionKey, 'Error', event) - if (global.STOP_TASK_GRACEFULLY === true) { + if (TS.projects.superalgos.globals.taskVariables.IS_TASK_STOPPING === true) { bot.STOP_SESSION = true parentLogger.write(MODULE_NAME, '[IMPORTANT] sessionError -> Stopping the Session now. ') } @@ -482,7 +482,7 @@ exports.newLearningSession = function newLearningSession(bot, parentLogger) { } global.EVENT_SERVER_CLIENT_MODULE.raiseEvent(bot.sessionKey, 'Warning', event) - if (global.STOP_TASK_GRACEFULLY === true) { + if (TS.projects.superalgos.globals.taskVariables.IS_TASK_STOPPING === true) { bot.STOP_SESSION = true parentLogger.write(MODULE_NAME, '[IMPORTANT] sessionWarning -> Stopping the Session now. ') } @@ -504,7 +504,7 @@ exports.newLearningSession = function newLearningSession(bot, parentLogger) { } global.EVENT_SERVER_CLIENT_MODULE.raiseEvent(bot.sessionKey, 'Info', event) - if (global.STOP_TASK_GRACEFULLY === true) { + if (TS.projects.superalgos.globals.taskVariables.IS_TASK_STOPPING === true) { bot.STOP_SESSION = true parentLogger.write(MODULE_NAME, '[IMPORTANT] sessionInfo -> Stopping the Session now. ') } diff --git a/TaskServer/LowFrequencyTrading/TradingProcess.js b/TaskServer/LowFrequencyTrading/TradingProcess.js index 526d31616..bad3a9ec6 100644 --- a/TaskServer/LowFrequencyTrading/TradingProcess.js +++ b/TaskServer/LowFrequencyTrading/TradingProcess.js @@ -536,7 +536,7 @@ function checkStopTaskGracefully() { /* Validation that we dont need to stop. */ - if (global.STOP_TASK_GRACEFULLY === true) { + if (TS.projects.superalgos.globals.taskVariables.IS_TASK_STOPPING === true) { return false } } diff --git a/TaskServer/LowFrequencyTrading/TradingSimulation.js b/TaskServer/LowFrequencyTrading/TradingSimulation.js index 9b572867d..9b6374946 100644 --- a/TaskServer/LowFrequencyTrading/TradingSimulation.js +++ b/TaskServer/LowFrequencyTrading/TradingSimulation.js @@ -200,7 +200,7 @@ exports.newTradingSimulation = function newTradingSimulation(bot, logger, tradin return } - if (global.STOP_TASK_GRACEFULLY === true) { + if (TS.projects.superalgos.globals.taskVariables.IS_TASK_STOPPING === true) { if (FULL_LOG === true) { logger.write(MODULE_NAME, '[INFO] runSimulation -> controlLoop -> We are going to stop here bacause we were requested to stop processing this task.') } updateEpisode('Task Stopped') breakLoop = true diff --git a/TaskServer/MultiPeriodDaily.js b/TaskServer/MultiPeriodDaily.js index 24824e889..2f6d1e87e 100644 --- a/TaskServer/MultiPeriodDaily.js +++ b/TaskServer/MultiPeriodDaily.js @@ -258,7 +258,7 @@ } function checkStopTaskGracefully() { /* Validation that we dont need to stop. */ - if (global.STOP_TASK_GRACEFULLY === true) { + if (TS.projects.superalgos.globals.taskVariables.IS_TASK_STOPPING === true) { callBackFunction(TS.projects.superalgos.globals.standardResponses.DEFAULT_OK_RESPONSE) return } diff --git a/TaskServer/NodeJsProcess.js b/TaskServer/NodeJsProcess.js index 2697c034c..0c31c5fb8 100644 --- a/TaskServer/NodeJsProcess.js +++ b/TaskServer/NodeJsProcess.js @@ -40,7 +40,7 @@ exports.newNodeJsProcess = function newNodeJsProcess() { process.on('message', message => { if (message === 'Stop this Task') { - global.STOP_TASK_GRACEFULLY = true; + TS.projects.superalgos.globals.taskVariables.IS_TASK_STOPPING = true; /* 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. diff --git a/TaskServer/ReinforcementLearning/LearningBot.js b/TaskServer/ReinforcementLearning/LearningBot.js index 1070e40f3..083293534 100644 --- a/TaskServer/ReinforcementLearning/LearningBot.js +++ b/TaskServer/ReinforcementLearning/LearningBot.js @@ -184,7 +184,7 @@ exports.newLearningBot = function newLearningBot(bot, parentLogger) { case TS.projects.superalgos.globals.standardResponses.DEFAULT_OK_RESPONSE.result: { logger.write(MODULE_NAME, "[INFO] run -> loop -> startProcessExecutionEvents -> onStarted -> Execution finished well."); - if (global.STOP_TASK_GRACEFULLY === true) { + if (TS.projects.superalgos.globals.taskVariables.IS_TASK_STOPPING === true) { loopControl() return } @@ -617,7 +617,7 @@ exports.newLearningBot = function newLearningBot(bot, parentLogger) { function shallWeStop(stopCallBack, continueCallBack) { try { /* IMPORTANT: This function is exactly the same on the 3 modules. */ - if (!global.STOP_TASK_GRACEFULLY) { + if (!TS.projects.superalgos.globals.taskVariables.IS_TASK_STOPPING) { continueCallBack(); } else { stopCallBack(); diff --git a/TaskServer/ReinforcementLearning/LearningProcess.js b/TaskServer/ReinforcementLearning/LearningProcess.js index fbeaf3146..b47a8557c 100644 --- a/TaskServer/ReinforcementLearning/LearningProcess.js +++ b/TaskServer/ReinforcementLearning/LearningProcess.js @@ -536,7 +536,7 @@ exports.newLearningProcess = function newLearningProcess(bot, logger, UTILITIES) function checkStopTaskGracefully() { /* Validation that we dont need to stop. */ - if (global.STOP_TASK_GRACEFULLY === true) { + if (TS.projects.superalgos.globals.taskVariables.IS_TASK_STOPPING === true) { return false } } diff --git a/TaskServer/SensorBot.js b/TaskServer/SensorBot.js index 02942b53f..18a71c060 100644 --- a/TaskServer/SensorBot.js +++ b/TaskServer/SensorBot.js @@ -207,7 +207,7 @@ case TS.projects.superalgos.globals.standardResponses.DEFAULT_OK_RESPONSE.result: { logger.write(MODULE_NAME, "[INFO] run -> loop -> startProcessExecutionEvents -> onStarted -> Execution finished well."); - if (global.STOP_TASK_GRACEFULLY === true) { + if (TS.projects.superalgos.globals.taskVariables.IS_TASK_STOPPING === true) { loopControl() return } @@ -541,7 +541,7 @@ function shallWeStop(stopCallBack, continueCallBack) { try { /* IMPORTANT: This function is exactly the same on the 3 modules. */ - if (!global.STOP_TASK_GRACEFULLY) { + if (!TS.projects.superalgos.globals.taskVariables.IS_TASK_STOPPING) { continueCallBack(); } else { stopCallBack(); diff --git a/TaskServer/TradingBot.js b/TaskServer/TradingBot.js index bd29d4cc6..1178fdbc7 100644 --- a/TaskServer/TradingBot.js +++ b/TaskServer/TradingBot.js @@ -184,7 +184,7 @@ case TS.projects.superalgos.globals.standardResponses.DEFAULT_OK_RESPONSE.result: { logger.write(MODULE_NAME, "[INFO] run -> loop -> startProcessExecutionEvents -> onStarted -> Execution finished well."); - if (global.STOP_TASK_GRACEFULLY === true) { + if (TS.projects.superalgos.globals.taskVariables.IS_TASK_STOPPING === true) { loopControl() return } @@ -617,7 +617,7 @@ function shallWeStop(stopCallBack, continueCallBack) { try { /* IMPORTANT: This function is exactly the same on the 3 modules. */ - if (!global.STOP_TASK_GRACEFULLY) { + if (!TS.projects.superalgos.globals.taskVariables.IS_TASK_STOPPING) { continueCallBack(); } else { stopCallBack(); diff --git a/TaskServer/TradingSession.js b/TaskServer/TradingSession.js index 4851740e7..549b3ed20 100644 --- a/TaskServer/TradingSession.js +++ b/TaskServer/TradingSession.js @@ -438,7 +438,7 @@ } global.EVENT_SERVER_CLIENT_MODULE.raiseEvent(bot.TRADING_SESSIONKey, 'Heartbeat', event) - if (global.STOP_TASK_GRACEFULLY === true) { + if (TS.projects.superalgos.globals.taskVariables.IS_TASK_STOPPING === true) { bot.STOP_SESSION = true parentLogger.write(MODULE_NAME, '[IMPORTANT] sessionHeartBeat -> Stopping the Session now. ') } @@ -460,7 +460,7 @@ } global.EVENT_SERVER_CLIENT_MODULE.raiseEvent(bot.TRADING_SESSIONKey, 'Error', event) - if (global.STOP_TASK_GRACEFULLY === true) { + if (TS.projects.superalgos.globals.taskVariables.IS_TASK_STOPPING === true) { bot.STOP_SESSION = true parentLogger.write(MODULE_NAME, '[IMPORTANT] sessionError -> Stopping the Session now. ') } @@ -482,7 +482,7 @@ } global.EVENT_SERVER_CLIENT_MODULE.raiseEvent(bot.TRADING_SESSIONKey, 'Warning', event) - if (global.STOP_TASK_GRACEFULLY === true) { + if (TS.projects.superalgos.globals.taskVariables.IS_TASK_STOPPING === true) { bot.STOP_SESSION = true parentLogger.write(MODULE_NAME, '[IMPORTANT] sessionWarning -> Stopping the Session now. ') } @@ -504,7 +504,7 @@ } global.EVENT_SERVER_CLIENT_MODULE.raiseEvent(bot.TRADING_SESSIONKey, 'Info', event) - if (global.STOP_TASK_GRACEFULLY === true) { + if (TS.projects.superalgos.globals.taskVariables.IS_TASK_STOPPING === true) { bot.STOP_SESSION = true parentLogger.write(MODULE_NAME, '[IMPORTANT] sessionInfo -> Stopping the Session now. ') }