diff --git a/Dashboard.js b/Dashboard.js index 80373e057..3d82092d0 100644 --- a/Dashboard.js +++ b/Dashboard.js @@ -88,7 +88,7 @@ function newDashboard () { function setBrowserEvents () { window.onbeforeunload = onBrowserClosed function onBrowserClosed () { - canvas.designerSpace.workspace.stopAllRunningTasks() + // canvas.designerSpace.workspace.stopAllRunningTasks() } } } diff --git a/DesignerSpace/Workspace/FunctionLibraries/UiObjectsFromNodes.js b/DesignerSpace/Workspace/FunctionLibraries/UiObjectsFromNodes.js index 591efb69a..fc5e63278 100644 --- a/DesignerSpace/Workspace/FunctionLibraries/UiObjectsFromNodes.js +++ b/DesignerSpace/Workspace/FunctionLibraries/UiObjectsFromNodes.js @@ -9,11 +9,13 @@ function newUiObjectsFromNodes () { let mapOfReferenceChildren = new Map() let mapOfNodes + let tasksToRun return thisObject function recreateWorkspace (node) { mapOfNodes = new Map() + tasksToRun = [] /* Create the workspace UI OBject and then continue with the root nodes. */ createUiObject(false, 'Workspace', node.name, node, undefined, undefined, 'Workspace') @@ -25,6 +27,16 @@ function newUiObjectsFromNodes () { } tryToConnectChildrenWithReferenceParents() + + setTimeout(runTasks, 70000) // We need to wait all tasks that were potentially running to stop + } + + function runTasks () { + for (let i = 0; i < tasksToRun.length; i++) { + let node = tasksToRun[i] + node.payload.uiObject.menu.internalClick('Run Task') + } + tasksToRun = undefined } function tryToConnectChildrenWithReferenceParents () { @@ -362,5 +374,11 @@ function newUiObjectsFromNodes () { canvas.floatingSpace.uiObjectConstructor.createUiObject(userAddingNew, payload) mapOfNodes.set(node.id, node) + + if (userAddingNew === false && uiObjectType === 'Task' && node.savedPayload !== undefined) { + if (node.savedPayload.uiObject.isRunning === true) { + tasksToRun.push(node) + } + } } } diff --git a/FloatingSpace/CircularProgressBar.js b/FloatingSpace/CircularProgressBar.js index 43a6e00c2..f7cc46136 100644 --- a/FloatingSpace/CircularProgressBar.js +++ b/FloatingSpace/CircularProgressBar.js @@ -23,13 +23,13 @@ function newCircularProgressBar () { let opacityCounters = [] - let eventSubscriptionHeartbeat + let eventSubscriptionIdHeartbeat return thisObject function finalize () { let key = thisObject.payload.node.name + '-' + thisObject.payload.node.type + '-' + thisObject.payload.node.id - systemEventHandler.stopListening(key, eventSubscriptionHeartbeat) + systemEventHandler.stopListening(key, eventSubscriptionIdHeartbeat) thisObject.container = undefined thisObject.payload = undefined @@ -52,6 +52,8 @@ function newCircularProgressBar () { } function onHeartBeat (message) { + if (thisObject.payload === undefined) { return } + if (thisObject.payload.uiObject === undefined) { return } opacityCounters[message.event.seconds] = 2000 thisObject.payload.uiObject.setValue(message.event.processingDate) } diff --git a/FloatingSpace/UiObject.js b/FloatingSpace/UiObject.js index c79b26d5f..13e20192f 100644 --- a/FloatingSpace/UiObject.js +++ b/FloatingSpace/UiObject.js @@ -94,9 +94,16 @@ function newUiObject () { let currentValue = 0 let rightDragging = false + let eventSubscriptionIdHeartbeat + let eventSubscriptionIdOnStopped + return thisObject function finalize () { + let key = thisObject.payload.node.name + '-' + thisObject.payload.node.type + '-' + thisObject.payload.node.id + systemEventHandler.stopListening(key, eventSubscriptionIdHeartbeat, 'UiObject') + systemEventHandler.stopListening(key, eventSubscriptionIdOnStopped, 'UiObject') + thisObject.container.eventHandler.stopListening(selfFocusEventSubscriptionId) thisObject.container.eventHandler.stopListening(selfNotFocuskEventSubscriptionId) thisObject.container.eventHandler.stopListening(selfDisplaceEventSubscriptionId) @@ -589,11 +596,19 @@ function newUiObject () { thisObject.circularProgressBar.fitFunction = thisObject.fitFunction thisObject.circularProgressBar.container = thisObject.container - /* We will wait to the event that the execution was terminated in order to call back the menu item */ + /* We will wait to hear the first onHeartBeat in order to confirm the execution was really started */ let key = thisObject.payload.node.name + '-' + thisObject.payload.node.type + '-' + thisObject.payload.node.id - systemEventHandler.listenToEvent(key, 'Running', undefined, key, undefined, onRunning) + systemEventHandler.listenToEvent(key, 'Heartbeat', undefined, 'UiObject', onResponse, onHeartBeat) + + function onResponse (message) { + eventSubscriptionIdHeartbeat = message.eventSubscriptionId + } + + function onHeartBeat () { + if (thisObject.payload === undefined) { return } + let key = thisObject.payload.node.name + '-' + thisObject.payload.node.type + '-' + thisObject.payload.node.id + systemEventHandler.stopListening(key, eventSubscriptionIdHeartbeat, 'UiObject') - function onRunning () { if (callBackFunction !== undefined) { callBackFunction(GLOBAL.DEFAULT_OK_RESPONSE) } @@ -621,9 +636,14 @@ function newUiObject () { function stop (callBackFunction, event) { /* We will wait to the event that the execution was terminated in order to call back the menu item */ let key = thisObject.payload.node.name + '-' + thisObject.payload.node.type + '-' + thisObject.payload.node.id - systemEventHandler.listenToEvent(key, 'Stopped', undefined, key, undefined, onStopped) + systemEventHandler.listenToEvent(key, 'Stopped', undefined, 'UiObject', onResponse, onStopped) + + function onResponse (message) { + eventSubscriptionIdOnStopped = message.eventSubscriptionId + } function onStopped () { + if (thisObject.payload === undefined) { return } if (callBackFunction !== undefined) { callBackFunction(GLOBAL.DEFAULT_OK_RESPONSE, event) }