From d9f4fef9ae0ac3bc6c77fe655d5d88cb87113812 Mon Sep 17 00:00:00 2001 From: Smidy13 <77650800+Smidy13@users.noreply.github.com> Date: Sun, 25 Apr 2021 21:23:23 +1200 Subject: [PATCH] Bug Fix: Trading Session getting stuck on Run Request Sent --- .../TradingSessionFunctions.js | 30 +++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/Projects/Superalgos/UI/Function-Libraries/TradingSessionFunctions.js b/Projects/Superalgos/UI/Function-Libraries/TradingSessionFunctions.js index b16c7e12d..b4e025336 100644 --- a/Projects/Superalgos/UI/Function-Libraries/TradingSessionFunctions.js +++ b/Projects/Superalgos/UI/Function-Libraries/TradingSessionFunctions.js @@ -56,10 +56,36 @@ function newSuperalgosFunctionLibraryTradingSessionFunctions() { let eventsServerClient = UI.projects.superalgos.spaces.designSpace.workspace.eventsServerClients.get(networkNode.id) - node.payload.uiObject.run(eventsServerClient, callBackFunction) - let key = node.name + '-' + node.type + '-' + node.id + /* Setup Listener to check Parent Task Status of the Session */ + let eventSubscriptionIdOnStatus + let eventHandlerKey = "Task Client - " + node.payload.parentNode.payload.parentNode.payload.parentNode.id + + eventsServerClient.listenToEvent(eventHandlerKey, 'Task Status', undefined, node.id, onResponse, onStatus) + + function onResponse(message) { + eventSubscriptionIdOnStatus = message.eventSubscriptionId + } + + function onStatus(message) { + eventsServerClient.stopListening(eventHandlerKey, eventSubscriptionIdOnStatus, node.id) + + /* If Task is Not Running Display Error */ + if (message.event.status === 'Task Process Not Running') { + node.payload.uiObject.setErrorMessage('Parent Task Not Running.') + callBackFunction(GLOBAL.DEFAULT_FAIL_RESPONSE) + } else { + node.payload.uiObject.run(eventsServerClient, callBackFunction) + } + } + + /* Raise Event to Check Task Status */ + let eventKey = {} + eventKey.taskId = node.payload.parentNode.payload.parentNode.payload.parentNode.id + + eventsServerClient.raiseEvent("Task Manager", 'Task Status', eventKey) + let lightingPath = '' + 'Trading System->' + 'Dynamic Indicators->Indicator Function->Formula->' +