Skip to content

Commit

Permalink
🐛 [Frontend] Do not duplicate poll calls (#6029)
Browse files Browse the repository at this point in the history
  • Loading branch information
odeimaiz authored Jul 4, 2024
1 parent a9d13d2 commit b2306b3
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
},

Expand All @@ -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();

Expand Down Expand Up @@ -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;
}

Expand All @@ -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) {
Expand All @@ -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");
}
Expand All @@ -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;
}
Expand All @@ -228,27 +246,24 @@ 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":
case "unknown":
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 {
Expand All @@ -260,6 +275,7 @@ qx.Class.define("osparc.data.model.IframeHandler", {
this.__retriesLeft = 40;
this.__waitForServiceReady(srvUrl);
}
pollingInNextStage = true;
break;
}
case "complete":
Expand All @@ -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;
}

Expand All @@ -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;
Expand All @@ -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}`);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(), {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(), {
Expand Down Expand Up @@ -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, {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit b2306b3

Please sign in to comment.