Process Variables

This commit is contained in:
Luis Fernando Molina committed 2020-11-27 20:43:49 +01:00
1 parent 5732f0dd3a
commit d3d66e6ada
5 files changed
+38 -32

No files matched your search

+6
View File
@@ -343,6 +343,12 @@
"propertyName": "timeConstants",
"functionName": "newSuperalgosGlobalsTimeConstants",
"fileName": "TimeConstants.js"
},
{
"name": "Process Variables",
"propertyName": "processVariables",
"functionName": "newSuperalgosGlobalsProcessVariables",
"fileName": "ProcessVariables.js"
}
],
"functionLibraries": [
@@ -4,7 +4,7 @@ exports.newSuperalgosFunctionLibrariesNodeJSFunctions = function () {
exitProcess: exitProcess
}
let isNodeJsProcessShuttingDown = false
let isNodeJsProcessShuttingDown = false
return thisObject
function exitProcess() {
@@ -13,7 +13,7 @@ exports.newSuperalgosFunctionLibrariesNodeJSFunctions = function () {
TS.projects.superalgos.functionLibraries.taskFunctions.taskError(undefined, "An unexpected error caused the Task to stop.")
}
if (isNodeJsProcessShuttingDown=== true) { return }
if (isNodeJsProcessShuttingDown === true) { return }
isNodeJsProcessShuttingDown = true
/* Signal that all sessions are stopping. */
@@ -32,9 +32,18 @@ exports.newSuperalgosFunctionLibrariesNodeJSFunctions = function () {
}
}
global.FINALIZE_LOGGERS()
//console.log("[INFO] Task Server -> " + global.TASK_NODE.name + " -> EXIT_NODE_PROCESS -> Task Server will stop in 10 seconds.");
finalizeLoggers()
setTimeout(process.exit, 10000) // We will give 10 seconds to logs be written on file
function finalizeLoggers() {
global.LOGGER_MAP.forEach(forEachLogger)
function forEachLogger(logger) {
if (logger !== undefined) {
logger.finalize()
}
}
}
}
}
@@ -0,0 +1,13 @@
exports.newSuperalgosGlobalsProcessVariables = function () {
/*
We need to count how many process instances we deployd and how many of them have already finished their job, either
because they just finished or because there was a request to stop the proceses. In this way, once we reach the
amount of instances started, we can safelly destroy the rest of the objects running and let this nodejs process die.
*/
let thisObject = {
ENDED_PROCESSES_COUNTER: 0,
TOTAL_PROCESS_INSTANCES_CREATED: 0
}
return thisObject
}
-20
View File
@@ -16,26 +16,6 @@ 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.FINALIZE_LOGGERS = function () {
global.LOGGER_MAP.forEach(forEachLogger)
function forEachLogger(logger) {
if (logger !== undefined) {
logger.finalize()
}
}
}
/*
We need to count how many process instances we deployd and how many of them have already finished their job, either
because they just finished or because there was a request to stop the proceses. In this way, once we reach the
amount of instances started, we can safelly destroy the rest of the objects running and let this nodejs process die.
*/
global.ENDED_PROCESSES_COUNTER = 0
global.TOTAL_PROCESS_INSTANCES_CREATED = 0
global.STOP_TASK_GRACEFULLY = false;
}
}
+6 -8
View File
@@ -212,7 +212,7 @@
function runSensorBot() {
try {
global.TOTAL_PROCESS_INSTANCES_CREATED++
TS.projects.superalgos.globals.processVariables.TOTAL_PROCESS_INSTANCES_CREATED++
global.LOGGER_MAP.set('runSensorBot', logger)
logger.bot = botConfig;
@@ -228,7 +228,7 @@
function runIndicatorBot() {
try {
global.TOTAL_PROCESS_INSTANCES_CREATED++
TS.projects.superalgos.globals.processVariables.TOTAL_PROCESS_INSTANCES_CREATED++
global.LOGGER_MAP.set('runIndicatorBot', logger)
logger.bot = botConfig;
@@ -245,7 +245,7 @@
function runTradingBot() {
global.TOTAL_PROCESS_INSTANCES_CREATED++
TS.projects.superalgos.globals.processVariables.TOTAL_PROCESS_INSTANCES_CREATED++
try {
global.LOGGER_MAP.set('runTradingBot', logger)
@@ -262,7 +262,7 @@
function runLearningBot() {
global.TOTAL_PROCESS_INSTANCES_CREATED++
TS.projects.superalgos.globals.processVariables.TOTAL_PROCESS_INSTANCES_CREATED++
try {
global.LOGGER_MAP.set('runLearningBot', logger)
@@ -317,11 +317,9 @@
}
function exitProcessInstance() {
TS.projects.superalgos.globals.processVariables.ENDED_PROCESSES_COUNTER++
global.ENDED_PROCESSES_COUNTER++
//console.log("[INFO] Task Server -> " + global.TASK_NODE.name + " -> exitProcessInstance -> Process #" + global.ENDED_PROCESSES_COUNTER + " from " + global.TOTAL_PROCESS_INSTANCES_CREATED + " exiting.");
if (global.ENDED_PROCESSES_COUNTER === global.TOTAL_PROCESS_INSTANCES_CREATED) {
if (TS.projects.superalgos.globals.processVariables.ENDED_PROCESSES_COUNTER === TS.projects.superalgos.globals.processVariables.TOTAL_PROCESS_INSTANCES_CREATED) {
TS.projects.superalgos.functionLibraries.nodeJSFunctions.exitProcess()
}
}