Session Syncronization

This commit is contained in:
Luis Fernando Molina committed 2020-09-25 20:20:14 +02:00
1 parent 80cd7cf54c
commit 47e6a5e468
4 files changed
+52 -37

No files matched your search

@@ -1,11 +1,41 @@
function newSessionFunctions() {
thisObject = {
syncronizeSessionWithBackEnd: syncronizeSessionWithBackEnd,
runSession: runSession,
stopSession: stopSession
}
return thisObject
function syncronizeSessionWithBackEnd(node) {
let networkNode = validations(node)
if (networkNode === undefined) {
/* Nodes that do not belong to a network can not get ready. */
return
}
let eventsServerClient = canvas.designSpace.workspace.eventsServerClients.get(networkNode.id)
/* First we setup everything so as to listen to the response from the Task Server */
let eventSubscriptionIdOnStatus
let key = node.name + '-' + node.type + '-' + node.id
eventsServerClient.listenToEvent(key, 'Status Response', undefined, node.id, onResponse, onStatus)
function onResponse(message) {
eventSubscriptionIdOnStatus = message.eventSubscriptionId
}
function onStatus(message) {
eventsServerClient.stopListening(key, eventSubscriptionIdOnStatus, node.id)
if (message.event.status === 'Session Runnning' ) {
node.payload.uiObject.menu.internalClick('Run Session')
}
}
/* Second we ask the Task Server if this Session is Running. */
eventsServerClient.raiseEvent(key, 'Session Status')
}
function runSession(node, functionLibraryProtocolNode, functionLibraryDependenciesFilter, resume, callBackFunction) {
let networkNode = validations(node)
if (networkNode === undefined) {
@@ -179,11 +209,6 @@ function newSessionFunctions() {
let networkNode = taskManager.payload.parentNode.payload.parentNode.payload.parentNode.payload.parentNode.payload.parentNode
if (node.payload.parentNode.payload.uiObject.isRunning !== true) {
node.payload.uiObject.setErrorMessage('Session needs a Process Instance parent to be running.')
return
}
if (node.tradingSystemReference === undefined) {
node.payload.uiObject.setErrorMessage('Session needs a child Trading System Reference.')
return
@@ -1,7 +1,7 @@
function newUiObjectsFromNodes() {
thisObject = {
syncronizeTasksFoundAtWorkspaceWithBackEnd: syncronizeTasksFoundAtWorkspaceWithBackEnd,
runSessions: runSessions,
syncronizeSessionsFoundAtWorkspaceWithBackEnd: syncronizeSessionsFoundAtWorkspaceWithBackEnd,
playTutorials: playTutorials,
recreateWorkspace: recreateWorkspace,
getNodeById: getNodeById,
@@ -14,7 +14,7 @@ function newUiObjectsFromNodes() {
let mapOfReferenceChildren = new Map()
let mapOfNodes
let tasksFoundAtWorkspace
let sessionsToRun
let sessionsFoundAtWorkspace
let tutorialsToPlay
return thisObject
@@ -26,7 +26,7 @@ function newUiObjectsFromNodes() {
function recreateWorkspace(node, callBackFunction) {
mapOfNodes = new Map()
tasksFoundAtWorkspace = []
sessionsToRun = []
sessionsFoundAtWorkspace = []
tutorialsToPlay = []
removeNullRootNodes()
@@ -158,12 +158,12 @@ function newUiObjectsFromNodes() {
tasksFoundAtWorkspace = undefined
}
function runSessions() {
for (let i = 0; i < sessionsToRun.length; i++) {
let node = sessionsToRun[i]
node.payload.uiObject.menu.internalClick('Run Session')
function syncronizeSessionsFoundAtWorkspaceWithBackEnd(functionLibrarySessionFunctions) {
for (let i = 0; i < sessionsFoundAtWorkspace.length; i++) {
let node = sessionsFoundAtWorkspace[i]
functionLibrarySessionFunctions.syncronizeSessionWithBackEnd(node)
}
sessionsToRun = undefined
sessionsFoundAtWorkspace = undefined
}
function playTutorials() {
@@ -635,12 +635,8 @@ function newUiObjectsFromNodes() {
/* Check if there are sessions to run */
if (userAddingNew === false && node.savedPayload !== undefined) {
if (uiObjectType === 'Live Trading Session' || uiObjectType === 'Forward Testing Session' || uiObjectType === 'Backtesting Session' || uiObjectType === 'Paper Trading Session') {
if (node.savedPayload.uiObject.isRunning === true) {
if (node.payload.parentNode !== undefined) {
if (sessionsToRun !== undefined) { // it might be undefined when you are spawning a session that was running while backed up
sessionsToRun.push(node)
}
}
if (sessionsFoundAtWorkspace !== undefined) { // it might be undefined when you are spawning a session that was running while backed up
sessionsFoundAtWorkspace.push(node)
}
}
}
+10 -17
View File
@@ -122,7 +122,7 @@ function newWorkspace() {
function finishInitialization() {
setupEventsServerClients()
runTasksAndSessions(false)
runTasksAndSessions()
thisObject.enabled = true
canvas.cockpitSpace.initializePosition()
canvas.splashScreen.initialize()
@@ -134,20 +134,13 @@ function newWorkspace() {
}
}
function runTasksAndSessions(replacingCurrentWorkspace) {
if (replacingCurrentWorkspace === true) {
functionLibraryUiObjectsFromNodes.syncronizeTasksFoundAtWorkspaceWithBackEnd(functionLibraryTaskFunctions)
// We give a few seconds for the tasks to start
setTimeout(functionLibraryUiObjectsFromNodes.runSessions, 80000)
// We give a few seconds
setTimeout(functionLibraryUiObjectsFromNodes.playTutorials, 3000)
} else {
functionLibraryUiObjectsFromNodes.syncronizeTasksFoundAtWorkspaceWithBackEnd(functionLibraryTaskFunctions)
// We give a few seconds for the tasks to start
setTimeout(functionLibraryUiObjectsFromNodes.runSessions, 10000)
// We give a few seconds
setTimeout(functionLibraryUiObjectsFromNodes.playTutorials, 1000)
}
function runTasksAndSessions() {
functionLibraryUiObjectsFromNodes.syncronizeTasksFoundAtWorkspaceWithBackEnd(functionLibraryTaskFunctions)
functionLibraryUiObjectsFromNodes.syncronizeSessionsFoundAtWorkspaceWithBackEnd(functionLibrarySessionFunctions)
setTimeout(functionLibraryUiObjectsFromNodes.playTutorials, 5000)
}
function setupEventsServerClients() {
@@ -294,9 +287,9 @@ function newWorkspace() {
break
case 5:
functionLibraryUiObjectsFromNodes.recreateWorkspace(thisObject.workspaceNode, finishInitialization)
function finishInitialization(){
function finishInitialization() {
setupEventsServerClients()
runTasksAndSessions(true)
runTasksAndSessions()
}
workingAtTask++
break
+2 -1
View File
@@ -980,7 +980,7 @@ function newUiObject() {
/* We will wait to hear the Running event in order to confirm the execution was really started */
let key = thisObject.payload.node.name + '-' + thisObject.payload.node.type + '-' + thisObject.payload.node.id
eventsServerClient.listenToEvent(key, 'Running', undefined, 'UiObject', onResponse, onRunning)
onRunningCallBackFunction = callBackFunction
function onResponse(message) {
@@ -988,6 +988,7 @@ function newUiObject() {
}
function onRunning() {
if (thisObject.payload === undefined) { return }
let key = thisObject.payload.node.name + '-' + thisObject.payload.node.type + '-' + thisObject.payload.node.id