From b2306b3793e80be0d3c656cb81c66b6f9dcaa3bb Mon Sep 17 00:00:00 2001 From: Odei Maiz <33152403+odeimaiz@users.noreply.github.com> Date: Thu, 4 Jul 2024 18:49:32 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20[Frontend]=20Do=20not=20duplicat?= =?UTF-8?q?e=20poll=20calls=20(#6029)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../class/osparc/data/model/IframeHandler.js | 42 +++++++++++++++---- .../class/osparc/desktop/WorkbenchView.js | 3 +- .../source/class/osparc/node/NodeView.js | 10 +++-- .../source/class/osparc/viewer/NodeViewer.js | 9 ++-- 4 files changed, 46 insertions(+), 18 deletions(-) diff --git a/services/static-webserver/client/source/class/osparc/data/model/IframeHandler.js b/services/static-webserver/client/source/class/osparc/data/model/IframeHandler.js index 2a077b2dff5..15d9e3f4b5a 100644 --- a/services/static-webserver/client/source/class/osparc/data/model/IframeHandler.js +++ b/services/static-webserver/client/source/class/osparc/data/model/IframeHandler.js @@ -51,6 +51,12 @@ qx.Class.define("osparc.data.model.IframeHandler", { check: "osparc.widget.PersistentIframe", init: null, nullable: true + }, + + polling: { + check: "Boolean", + init: null, + nullable: true } }, @@ -64,6 +70,11 @@ qx.Class.define("osparc.data.model.IframeHandler", { __retriesLeft: null, startPolling: function() { + if (this.isPolling()) { + return; + } + this.setPolling(true); + this.getNode().getStatus().getProgressSequence() .resetSequence(); @@ -146,10 +157,12 @@ qx.Class.define("osparc.data.model.IframeHandler", { __nodeState: function(starting=true) { // Check if study is still there if (this.getStudy() === null || this.__stopRequestingStatus === true) { + this.setPolling(false); return; } // Check if node is still there if (this.getStudy().getWorkbench().getNode(this.getNode().getNodeId()) === null) { + this.setPolling(false); return; } @@ -176,6 +189,7 @@ qx.Class.define("osparc.data.model.IframeHandler", { }; node.fireDataEvent("showInLogger", errorMsgData); if ("status" in err && err.status === 406) { + this.setPolling(false); return; } if (this.__unresponsiveRetries > 0) { @@ -190,6 +204,7 @@ qx.Class.define("osparc.data.model.IframeHandler", { const interval = Math.floor(Math.random() * 5000) + 3000; setTimeout(() => this.__nodeState(), interval); } else { + this.setPolling(false); node.getStatus().setInteractive("failed"); osparc.FlashMessenger.getInstance().logAs(this.tr("There was an error starting") + " " + node.getLabel(), "ERROR"); } @@ -201,14 +216,17 @@ qx.Class.define("osparc.data.model.IframeHandler", { const nodeId = data["service_uuid"]; const node = this.getNode(); const status = node.getStatus(); + let nextPollIn = null; + let pollingInNextStage = null; switch (serviceState) { case "idle": { status.setInteractive(serviceState); if (starting && this.__unresponsiveRetries>0) { // a bit of a hack. We will get rid of it when the backend pushes the states this.__unresponsiveRetries--; - const interval = 2000; - qx.event.Timer.once(() => this.__nodeState(starting), this, interval); + nextPollIn = 2000; + } else { + this.setPolling(false); } break; } @@ -228,8 +246,7 @@ qx.Class.define("osparc.data.model.IframeHandler", { node.fireDataEvent("showInLogger", msgData); } status.setInteractive(serviceState); - const interval = 10000; - qx.event.Timer.once(() => this.__nodeState(starting), this, interval); + nextPollIn = 10000; break; } case "stopping": @@ -237,18 +254,16 @@ qx.Class.define("osparc.data.model.IframeHandler", { case "starting": case "pulling": { status.setInteractive(serviceState); - const interval = 5000; - qx.event.Timer.once(() => this.__nodeState(starting), this, interval); + nextPollIn = 5000; break; } case "running": { if (nodeId !== node.getNodeId()) { - return; + break; } if (!starting) { status.setInteractive("stopping"); - const interval = 5000; - qx.event.Timer.once(() => this.__nodeState(starting), this, interval); + nextPollIn = 5000; break; } const { @@ -260,6 +275,7 @@ qx.Class.define("osparc.data.model.IframeHandler", { this.__retriesLeft = 40; this.__waitForServiceReady(srvUrl); } + pollingInNextStage = true; break; } case "complete": @@ -279,12 +295,18 @@ qx.Class.define("osparc.data.model.IframeHandler", { console.error(serviceState, "service state not supported"); break; } + if (nextPollIn) { + qx.event.Timer.once(() => this.__nodeState(starting), this, nextPollIn); + } else if (pollingInNextStage !== true) { + this.setPolling(false); + } }, __waitForServiceReady: function(srvUrl) { this.getNode().getStatus().setInteractive("connecting"); if (this.__retriesLeft === 0) { + this.setPolling(false); return; } @@ -293,6 +315,7 @@ qx.Class.define("osparc.data.model.IframeHandler", { // Check if node is still there if (this.getStudy().getWorkbench().getNode(this.getNode().getNodeId()) === null) { + this.setPolling(false); return; } const interval = 5000; @@ -310,6 +333,7 @@ qx.Class.define("osparc.data.model.IframeHandler", { console.log("Connecting: fetch's response status", response.status); } if (response.status < 400) { + this.setPolling(false); this.__serviceReadyIn(srvUrl); } else { console.log(`Connecting: ${srvUrl} is not reachable. Status: ${response.status}`); diff --git a/services/static-webserver/client/source/class/osparc/desktop/WorkbenchView.js b/services/static-webserver/client/source/class/osparc/desktop/WorkbenchView.js index 2b86040f481..4d974e33d66 100644 --- a/services/static-webserver/client/source/class/osparc/desktop/WorkbenchView.js +++ b/services/static-webserver/client/source/class/osparc/desktop/WorkbenchView.js @@ -725,10 +725,9 @@ qx.Class.define("osparc.desktop.WorkbenchView", { widget.addListener("restore", () => this.setMaximized(false), this); } }); - this.__iFrameChanged(node); - node.getIframeHandler().addListener("iframeChanged", () => this.__iFrameChanged(node), this); iFrame.addListener("load", () => this.__iFrameChanged(node), this); + this.__iFrameChanged(node); } else { // This will keep what comes after at the bottom this.__iframePage.add(new qx.ui.core.Spacer(), { diff --git a/services/static-webserver/client/source/class/osparc/node/NodeView.js b/services/static-webserver/client/source/class/osparc/node/NodeView.js index ed9f92f095c..93e115e1ad8 100644 --- a/services/static-webserver/client/source/class/osparc/node/NodeView.js +++ b/services/static-webserver/client/source/class/osparc/node/NodeView.js @@ -74,8 +74,10 @@ qx.Class.define("osparc.node.NodeView", { const loadingPage = this.getNode().getLoadingPage(); const iFrame = this.getNode().getIFrame(); if (loadingPage && iFrame) { - this.__iFrameChanged(); + const node = this.getNode(); + node.getIframeHandler().addListener("iframeChanged", () => this.__iFrameChanged(), this); iFrame.addListener("load", () => this.__iFrameChanged()); + this.__iFrameChanged(); } else { // This will keep what comes after at the bottom this._iFrameLayout.add(new qx.ui.core.Spacer(), { @@ -150,8 +152,10 @@ qx.Class.define("osparc.node.NodeView", { __iFrameChanged: function() { this._iFrameLayout.removeAll(); - const loadingPage = this.getNode().getLoadingPage(); - const iFrame = this.getNode().getIFrame(); + const node = this.getNode(); + + const loadingPage = node.getLoadingPage(); + const iFrame = node.getIFrame(); const src = iFrame.getSource(); const iFrameView = (src === null || src === "about:blank") ? loadingPage : iFrame; this._iFrameLayout.add(iFrameView, { diff --git a/services/static-webserver/client/source/class/osparc/viewer/NodeViewer.js b/services/static-webserver/client/source/class/osparc/viewer/NodeViewer.js index 9023e6cc5f2..1b7422d06f3 100644 --- a/services/static-webserver/client/source/class/osparc/viewer/NodeViewer.js +++ b/services/static-webserver/client/source/class/osparc/viewer/NodeViewer.js @@ -51,9 +51,9 @@ qx.Class.define("osparc.viewer.NodeViewer", { const iframeHandler = node.getIframeHandler(); if (iframeHandler) { iframeHandler.startPolling(); - iframeHandler.addListener("iframeChanged", () => this.__buildLayout(), this); - iframeHandler.getIFrame().addListener("load", () => this.__buildLayout(), this); - this.__buildLayout(); + iframeHandler.addListener("iframeChanged", () => this.__iFrameChanged(), this); + iframeHandler.getIFrame().addListener("load", () => this.__iFrameChanged(), this); + this.__iFrameChanged(); this.__attachSocketEventHandlers(); } @@ -89,10 +89,11 @@ qx.Class.define("osparc.viewer.NodeViewer", { }, members: { - __buildLayout: function() { + __iFrameChanged: function() { this._removeAll(); const iframeHandler = this.getNode().getIframeHandler(); + const loadingPage = iframeHandler.getLoadingPage(); const iFrame = iframeHandler.getIFrame(); const src = iFrame.getSource();