Network Error Improvements

This commit is contained in:
Luis Fernando Molina committed 2020-08-23 09:40:18 +02:00
1 parent 10307d60e5
commit 2f386cbdef
3 files changed
+52 -8

No files matched your search

+23 -5
View File
@@ -67,6 +67,7 @@ function newWorkspace() {
thisObject.nodeChildren = newNodeChildren()
let savingWorkspaceIntervalId
let isInitialized = false
let workingAtTask = 0
let circularProgressBar = newBusyProgressBar()
@@ -118,7 +119,7 @@ function newWorkspace() {
thisObject.enabled = true
canvas.cockpitSpace.initializePosition()
canvas.splashScreen.initialize()
setInterval(saveWorkspace, 60000)
savingWorkspaceIntervalId = setInterval(saveWorkspace, 60000)
isInitialized = true
}
} catch (err) {
@@ -162,7 +163,7 @@ function newWorkspace() {
if (host === undefined) { host = 'localhost' }
if (webSocketsPort === undefined) { webSocketsPort = '8080' }
let eventsServerClient = newEventsServerClient(host, webSocketsPort, networkNode.name)
let eventsServerClient = newEventsServerClient(host, webSocketsPort, networkNode.name, networkNode)
eventsServerClient.initialize()
thisObject.eventsServerClients.set(networkNode.id, eventsServerClient)
@@ -233,6 +234,14 @@ function newWorkspace() {
}
}
function finalizeEventsServerClients() {
thisObject.eventsServerClients.forEach(finalize)
function finalize(eventServerClient) {
eventServerClient.finalize()
}
}
function replacingWorkspacePhysics() {
if (thisObject.enabled !== true) { return }
@@ -249,21 +258,30 @@ function newWorkspace() {
workingAtTask++
break
case 3:
finalizeEventsServerClients()
thisObject.eventsServerClients = new Map()
workingAtTask++
break
case 4:
clearInterval(savingWorkspaceIntervalId)
workingAtTask++
break
case 5:
thisObject.workspaceNode = loadedWorkspaceNode
loadedWorkspaceNode = undefined
workingAtTask++
break
case 4:
case 6:
functionLibraryUiObjectsFromNodes.recreateWorkspace(thisObject.workspaceNode)
setupEventsServerClients()
runTasksAndSessions(true)
workingAtTask++
break
case 5:
case 7:
canvas.chartingSpace.reset()
workingAtTask++
break
case 6:
case 8:
workingAtTask = 0
circularProgressBar.visible = false
break
+24 -2
View File
@@ -1,5 +1,5 @@
function newEventsServerClient(host, port, hostName) {
function newEventsServerClient(host, port, hostName, networkNode) {
/* Web Sockets Connection */
const MODULE_NAME = 'System Event Handler'
@@ -17,6 +17,7 @@ function newEventsServerClient(host, port, hostName) {
let thisObject = {
isConnected: isConnected,
initialize: initialize,
finalize: finalize,
physics: physics,
createEventHandler: createEventHandler,
deleteEventHandler: deleteEventHandler,
@@ -37,6 +38,21 @@ function newEventsServerClient(host, port, hostName) {
setuptWebSockets(callBackFunction)
}
function finalize() {
WEB_SOCKETS_CONNECTION.close()
WEB_SOCKETS_CONNECTION.onerror = undefined
WEB_SOCKETS_CONNECTION.onmessage = undefined
WEB_SOCKETS_CONNECTION.onopen = undefined
WEB_SOCKETS_CONNECTION = undefined
eventListeners = undefined
responseWaiters = undefined
commandsWaitingConfirmation = undefined
commandsSentByTimestamp = undefined
nonce = undefined
thisObject = undefined
}
function isConnected() {
if (WEB_SOCKETS_CONNECTION.readyState === 1) {
return true
@@ -156,7 +172,13 @@ function newEventsServerClient(host, port, hostName) {
}
if (thisObject.isConnected() !== true) {
canvas.cockpitSpace.setStatus('Connecting to Superalgos Backend at ' + hostName + ' Network Node. Please wait until the connection is established.', 100, canvas.cockpitSpace.statusTypes.WARNING)
if (networkNode !== undefined) {
if (networkNode.payload !== undefined) {
if (networkNode.payload.uiObject !== undefined) {
networkNode.payload.uiObject.setErrorMessage('Connecting to Superalgos Backend at ' + hostName + ' Network Node')
}
}
}
} else {
retryCommandsPhysics()
}
@@ -349,6 +349,10 @@
function trimDataFile(dataFile, recordDefinition) {
/*
Here we will discard all the records in a file that are outside of the current time range.
We will include the las element previous to the begining of the time range. This is needed
because during the simulation, the current period is not the open one, but the previous to
the open, and if we do not include the previous to the initial datetime there will be no
current objects at the begining of the simulation for many time frames.
*/
let beginIndex
let endIndex
@@ -366,7 +370,7 @@
let dataRecord = dataFile[i]
let begin = dataRecord[beginIndex]
let end = dataRecord[endIndex]
if (end < bot.SESSION.parameters.timeRange.config.initialDatetime - 1) { continue } // /1 because we need the previous closed element
if (end + timeFrame < bot.SESSION.parameters.timeRange.config.initialDatetime - 1) { continue } // /1 because we need the previous closed element
if (begin > bot.SESSION.parameters.timeRange.config.finalDatetime) { continue }
result.push(dataRecord)
}