Session and Task Syncronization with the backend
This commit is contained in:
1 parent
1c2a335f6f
commit
ec4450f0fe
10 files changed
+115
-75
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,6 +1,6 @@
|
||||
function newTaskFunctions() {
|
||||
thisObject = {
|
||||
getReady: getReady,
|
||||
syncronizeTaskWithBackEnd: syncronizeTaskWithBackEnd,
|
||||
|
||||
runTask: runTask,
|
||||
stopTask: stopTask,
|
||||
@@ -35,7 +35,7 @@ function newTaskFunctions() {
|
||||
|
||||
return thisObject
|
||||
|
||||
function getReady(node) {
|
||||
function syncronizeTaskWithBackEnd(node) {
|
||||
let networkNode = validations(node)
|
||||
if (networkNode === undefined) {
|
||||
/* Nodes that do not belong to a network can not get ready. */
|
||||
@@ -56,7 +56,7 @@ function newTaskFunctions() {
|
||||
function onStatus(message) {
|
||||
eventsServerClient.stopListening(key, eventSubscriptionIdOnStatus, node.id)
|
||||
if (message.event.status === 'Task Process Running' ) {
|
||||
node.payload.uiObject.run()
|
||||
node.payload.uiObject.menu.internalClick('Run Task')
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
function newUiObjectsFromNodes() {
|
||||
thisObject = {
|
||||
runTasks: runTasks,
|
||||
runSessions: runSessions,
|
||||
syncronizeTasksFoundAtWorkspaceWithBackEnd: syncronizeTasksFoundAtWorkspaceWithBackEnd,
|
||||
syncronizeSessionsFoundAtWorkspaceWithBackEnd: syncronizeSessionsFoundAtWorkspaceWithBackEnd,
|
||||
playTutorials: playTutorials,
|
||||
recreateWorkspace: recreateWorkspace,
|
||||
getNodeById: getNodeById,
|
||||
@@ -13,8 +13,8 @@ function newUiObjectsFromNodes() {
|
||||
|
||||
let mapOfReferenceChildren = new Map()
|
||||
let mapOfNodes
|
||||
let tasksToRun
|
||||
let sessionsToRun
|
||||
let tasksFoundAtWorkspace
|
||||
let sessionsFoundAtWorkspace
|
||||
let tutorialsToPlay
|
||||
|
||||
return thisObject
|
||||
@@ -25,8 +25,8 @@ function newUiObjectsFromNodes() {
|
||||
|
||||
function recreateWorkspace(node, callBackFunction) {
|
||||
mapOfNodes = new Map()
|
||||
tasksToRun = []
|
||||
sessionsToRun = []
|
||||
tasksFoundAtWorkspace = []
|
||||
sessionsFoundAtWorkspace = []
|
||||
tutorialsToPlay = []
|
||||
|
||||
removeNullRootNodes()
|
||||
@@ -150,20 +150,20 @@ function newUiObjectsFromNodes() {
|
||||
}
|
||||
}
|
||||
|
||||
function runTasks() {
|
||||
for (let i = 0; i < tasksToRun.length; i++) {
|
||||
let node = tasksToRun[i]
|
||||
node.payload.uiObject.menu.internalClick('Run Task')
|
||||
function syncronizeTasksFoundAtWorkspaceWithBackEnd(functionLibraryTaskFunctions) {
|
||||
for (let i = 0; i < tasksFoundAtWorkspace.length; i++) {
|
||||
let node = tasksFoundAtWorkspace[i]
|
||||
functionLibraryTaskFunctions.syncronizeTaskWithBackEnd(node)
|
||||
}
|
||||
tasksToRun = undefined
|
||||
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() {
|
||||
@@ -625,26 +625,18 @@ function newUiObjectsFromNodes() {
|
||||
/* This is the point where we build a map with all nodes present at the workspace */
|
||||
mapOfNodes.set(node.id, node)
|
||||
|
||||
/* Check if there are tasks to run */
|
||||
/* We will collect all tasks at the workspace in order to later syncronize them with the backend */
|
||||
if (userAddingNew === false && uiObjectType === 'Task' && node.savedPayload !== undefined) {
|
||||
if (node.savedPayload.uiObject.isRunning === true) {
|
||||
if (node.payload.parentNode !== undefined) {
|
||||
if (tasksToRun !== undefined) { // it might be undefined when you are spawning a task that was running while backed up
|
||||
tasksToRun.push(node)
|
||||
}
|
||||
}
|
||||
if (tasksFoundAtWorkspace !== undefined) { // it might be undefined when you are spawning a task that was backed up
|
||||
tasksFoundAtWorkspace.push(node)
|
||||
}
|
||||
}
|
||||
|
||||
/* 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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user