diff --git a/TaskServer/IndicatorBot.js b/TaskServer/IndicatorBot.js index 14616eeb3..a4a858d9f 100644 --- a/TaskServer/IndicatorBot.js +++ b/TaskServer/IndicatorBot.js @@ -84,16 +84,10 @@ function run(callBackFunction) { try { - let fixedTimeLoopIntervalHandle; - /* Heartbeats sent to the UI */ bot.processHeartBeat = processHeartBeat - if (bot.runAtFixedInterval === true) { - fixedTimeLoopIntervalHandle = setInterval(loop, bot.fixedInterval); - } else { - loop(); - } + loop(); function loop() { try { @@ -769,7 +763,6 @@ global.EVENT_SERVER_CLIENT_MODULE.raiseEvent(TS.projects.superalgos.globals.processVariables.VARIABLES_BY_PROCESS_INDEX_MAP.get(processIndex).KEY_FOR_EVENTS, 'Stopped') } logger.persist(); - clearInterval(fixedTimeLoopIntervalHandle); clearTimeout(nextLoopTimeoutHandle); if (global.unexpectedError !== undefined) { callBackFunction(TS.projects.superalgos.globals.standardResponses.DEFAULT_FAIL_RESPONSE) @@ -780,7 +773,6 @@ } catch (err) { parentLogger.write(MODULE_NAME, "[ERROR] run -> err = " + err.stack); - clearInterval(fixedTimeLoopIntervalHandle); clearTimeout(nextLoopTimeoutHandle); callBackFunction(TS.projects.superalgos.globals.standardResponses.DEFAULT_FAIL_RESPONSE); } diff --git a/TaskServer/ProcessInstance.js b/TaskServer/ProcessInstance.js index 1bb246182..78fbe8916 100644 --- a/TaskServer/ProcessInstance.js +++ b/TaskServer/ProcessInstance.js @@ -98,112 +98,27 @@ } } - if (processConfig.startMode === undefined) { // Default + botConfig.hasTheBotJustStarted = true; - botConfig.hasTheBotJustStarted = true; - - switch (TS.projects.superalgos.globals.taskConstants.TASK_NODE.bot.processes[processIndex].referenceParent.parentNode.type) { - case 'Sensor Bot': { - runSensorBot() - break; - } - case 'Indicator Bot': { - runIndicatorBot() - break; - } - case 'Trading Bot': { - runTradingBot() - break; - } - case 'Learning Bot': { - runLearningBot() - break; - } - default: { - console.log(logDisplace + "Process Instance : [ERROR] start -> Unexpected bot type. -> TS.projects.superalgos.globals.taskConstants.TASK_NODE.bot.processes[processIndex].referenceParent.parentNode.type = " + TS.projects.superalgos.globals.taskConstants.TASK_NODE.bot.processes[processIndex].referenceParent.parentNode.type); - } + switch (TS.projects.superalgos.globals.taskConstants.TASK_NODE.bot.processes[processIndex].referenceParent.parentNode.type) { + case 'Sensor Bot': { + runSensorBot() + break; } - return - } - - if (processConfig.startMode.noTime !== undefined) { - - if (processConfig.startMode.noTime.run === "true") { - - if (processConfig.startMode.noTime.resumeExecution === true) { - botConfig.hasTheBotJustStarted = false; - } else { - botConfig.hasTheBotJustStarted = true; - } - - switch (TS.projects.superalgos.globals.taskConstants.TASK_NODE.bot.processes[processIndex].referenceParent.parentNode.type) { - case 'Sensor Bot': { - runSensorBot() - break; - } - case 'Indicator Bot': { - runIndicatorBot() - break; - } - case 'Trading Bot': { - runTradingBot() - break; - } - case 'Learning Bot': { - runLearningBot() - break; - } - default: { - console.log(logDisplace + "Process Instance : [ERROR] start -> Unexpected bot type. -> TS.projects.superalgos.globals.taskConstants.TASK_NODE.bot.processes[processIndex].referenceParent.parentNode.type = " + TS.projects.superalgos.globals.taskConstants.TASK_NODE.bot.processes[processIndex].referenceParent.parentNode.type); - } - } + case 'Indicator Bot': { + runIndicatorBot() + break; } - } - - if (processConfig.startMode.fixedInterval !== undefined) { - - if (processConfig.startMode.fixedInterval.run === "true") { - - botConfig.runAtFixedInterval = true; - botConfig.fixedInterval = processConfig.startMode.fixedInterval.interval; - - switch (TS.projects.superalgos.globals.taskConstants.TASK_NODE.bot.processes[processIndex].referenceParent.parentNode.type) { - case 'Sensor Bot': { - runSensorBot() - break; - } - default: { - console.log(logDisplace + "Process Instance : [ERROR] start -> Unexpected bot type. -> TS.projects.superalgos.globals.taskConstants.TASK_NODE.bot.processes[processIndex].referenceParent.parentNode.type = " + TS.projects.superalgos.globals.taskConstants.TASK_NODE.bot.processes[processIndex].referenceParent.parentNode.type); - } - } + case 'Trading Bot': { + runTradingBot() + break; } - } - - if (processConfig.startMode.userDefined !== undefined) { - - if (processConfig.startMode.userDefined.run === "true") { - - botConfig.startMode = "User Defined"; - - if (processConfig.startMode.userDefined.resumeExecution === true) { - botConfig.hasTheBotJustStarted = false; - } else { - botConfig.hasTheBotJustStarted = true; - } - - switch (TS.projects.superalgos.globals.taskConstants.TASK_NODE.bot.processes[processIndex].referenceParent.parentNode.type) { - case 'Trading Bot': { - runTradingBot(processConfig); - break; - } - case 'Learning Bot': { - runLearningBot(processConfig); - break; - } - default: { - console.log(logDisplace + "Process Instance : [ERROR] start -> Unexpected bot type. -> TS.projects.superalgos.globals.taskConstants.TASK_NODE.bot.processes[processIndex].referenceParent.parentNode.type = " + TS.projects.superalgos.globals.taskConstants.TASK_NODE.bot.processes[processIndex].referenceParent.parentNode.type); - } - } + case 'Learning Bot': { + runLearningBot() + break; + } + default: { + console.log(logDisplace + "Process Instance : [ERROR] start -> Unexpected bot type. -> TS.projects.superalgos.globals.taskConstants.TASK_NODE.bot.processes[processIndex].referenceParent.parentNode.type = " + TS.projects.superalgos.globals.taskConstants.TASK_NODE.bot.processes[processIndex].referenceParent.parentNode.type); } } diff --git a/TaskServer/ReinforcementLearning/LearningBot.js b/TaskServer/ReinforcementLearning/LearningBot.js index 7f1e5806f..c4204af1f 100644 --- a/TaskServer/ReinforcementLearning/LearningBot.js +++ b/TaskServer/ReinforcementLearning/LearningBot.js @@ -42,7 +42,6 @@ exports.newLearningBot = function (processIndex, bot, parentLogger) { function run(callBackFunction) { try { /* Some initial values*/ - let fixedTimeLoopIntervalHandle; bot.STOP_SESSION = true; if (FULL_LOG === true) { parentLogger.write(MODULE_NAME, '[IMPORTANT] run -> Stopping the Session now. ') } @@ -655,7 +654,6 @@ exports.newLearningBot = function (processIndex, bot, parentLogger) { } sessionStopped() logger.persist(); - clearInterval(fixedTimeLoopIntervalHandle); clearTimeout(nextLoopTimeoutHandle); if (global.unexpectedError !== undefined) { callBackFunction(TS.projects.superalgos.globals.standardResponses.DEFAULT_FAIL_RESPONSE) @@ -673,7 +671,6 @@ exports.newLearningBot = function (processIndex, bot, parentLogger) { } catch (err) { parentLogger.write(MODULE_NAME, "[ERROR] run -> err = " + err.stack); - clearInterval(fixedTimeLoopIntervalHandle); clearTimeout(nextLoopTimeoutHandle); callBackFunction(TS.projects.superalgos.globals.standardResponses.DEFAULT_FAIL_RESPONSE); } diff --git a/TaskServer/SensorBot.js b/TaskServer/SensorBot.js index 8b01eb4e1..f6abdc884 100644 --- a/TaskServer/SensorBot.js +++ b/TaskServer/SensorBot.js @@ -89,17 +89,10 @@ function run(callBackFunction) { try { - let fixedTimeLoopIntervalHandle; - /* Heartbeats sent to the UI */ bot.processHeartBeat = processHeartBeat - if (bot.runAtFixedInterval === true) { - fixedTimeLoopIntervalHandle = setInterval(loop, bot.fixedInterval); - loop(); // First run. - } else { - loop(); - } + loop(); function loop() { try { @@ -508,29 +501,17 @@ } break; case 'Sleep': { - if (bot.runAtFixedInterval === true) { - logger.write(MODULE_NAME, "[INFO] run -> loop -> loopControl -> Fixed Interval Sleep exit point reached.") - logger.persist(); - return; - } else { - logger.write(MODULE_NAME, "[INFO] run -> loop -> loopControl -> Restarting Loop in " + (processConfig.sleepWaitTime / 60000) + " minutes.") - nextLoopTimeoutHandle = setTimeout(loop, processConfig.sleepWaitTime); - processHeartBeat(undefined, undefined, "Waiting " + processConfig.sleepWaitTime / 60000 + " minutes for next execution.") - logger.persist(); - } + logger.write(MODULE_NAME, "[INFO] run -> loop -> loopControl -> Restarting Loop in " + (processConfig.sleepWaitTime / 60000) + " minutes.") + nextLoopTimeoutHandle = setTimeout(loop, processConfig.sleepWaitTime); + processHeartBeat(undefined, undefined, "Waiting " + processConfig.sleepWaitTime / 60000 + " minutes for next execution.") + logger.persist(); } break; case 'Coma': { - if (bot.runAtFixedInterval === true) { - logger.write(MODULE_NAME, "[INFO] run -> loop -> loopControl -> Fixed Interval Coma exit point reached.") - logger.persist(); - return; - } else { - logger.write(MODULE_NAME, "[INFO] run -> loop -> loopControl -> Restarting Loop in " + (processConfig.comaWaitTime / 3600000) + " hours.") - nextLoopTimeoutHandle = setTimeout(loop, processConfig.comaWaitTime); - processHeartBeat(undefined, undefined, "Waiting " + processConfig.comaWaitTime / 3600000 + " hours for next execution.") - logger.persist(); - } + logger.write(MODULE_NAME, "[INFO] run -> loop -> loopControl -> Restarting Loop in " + (processConfig.comaWaitTime / 3600000) + " hours.") + nextLoopTimeoutHandle = setTimeout(loop, processConfig.comaWaitTime); + processHeartBeat(undefined, undefined, "Waiting " + processConfig.comaWaitTime / 3600000 + " hours for next execution.") + logger.persist(); } break; } @@ -578,7 +559,6 @@ global.EVENT_SERVER_CLIENT_MODULE.raiseEvent(TS.projects.superalgos.globals.processVariables.VARIABLES_BY_PROCESS_INDEX_MAP.get(processIndex).KEY_FOR_EVENTS, 'Stopped') } logger.persist(); - clearInterval(fixedTimeLoopIntervalHandle); clearTimeout(nextLoopTimeoutHandle); if (global.unexpectedError !== undefined) { callBackFunction(TS.projects.superalgos.globals.standardResponses.DEFAULT_FAIL_RESPONSE) @@ -590,7 +570,6 @@ catch (err) { parentLogger.write(MODULE_NAME, "[ERROR] run -> err = " + err.stack); - clearInterval(fixedTimeLoopIntervalHandle); clearTimeout(nextLoopTimeoutHandle); callBackFunction(TS.projects.superalgos.globals.standardResponses.DEFAULT_FAIL_RESPONSE); } diff --git a/TaskServer/TradingBot.js b/TaskServer/TradingBot.js index ee594bf8a..cd74b8d74 100644 --- a/TaskServer/TradingBot.js +++ b/TaskServer/TradingBot.js @@ -42,7 +42,6 @@ function run(callBackFunction) { try { /* Some initial values*/ - let fixedTimeLoopIntervalHandle; bot.STOP_SESSION = true; parentLogger.write(MODULE_NAME, '[IMPORTANT] run -> Stopping the Session now. ') @@ -655,7 +654,6 @@ } sessionStopped() logger.persist(); - clearInterval(fixedTimeLoopIntervalHandle); clearTimeout(nextLoopTimeoutHandle); if (global.unexpectedError !== undefined) { callBackFunction(TS.projects.superalgos.globals.standardResponses.DEFAULT_FAIL_RESPONSE) @@ -673,7 +671,6 @@ } catch (err) { parentLogger.write(MODULE_NAME, "[ERROR] run -> err = " + err.stack); - clearInterval(fixedTimeLoopIntervalHandle); clearTimeout(nextLoopTimeoutHandle); callBackFunction(TS.projects.superalgos.globals.standardResponses.DEFAULT_FAIL_RESPONSE); }