Skip to content

Commit b2306b3

Browse files
authored
🐛 [Frontend] Do not duplicate poll calls (#6029)
1 parent a9d13d2 commit b2306b3

File tree

4 files changed

+46
-18
lines changed

4 files changed

+46
-18
lines changed

services/static-webserver/client/source/class/osparc/data/model/IframeHandler.js

Lines changed: 33 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,12 @@ qx.Class.define("osparc.data.model.IframeHandler", {
5151
check: "osparc.widget.PersistentIframe",
5252
init: null,
5353
nullable: true
54+
},
55+
56+
polling: {
57+
check: "Boolean",
58+
init: null,
59+
nullable: true
5460
}
5561
},
5662

@@ -64,6 +70,11 @@ qx.Class.define("osparc.data.model.IframeHandler", {
6470
__retriesLeft: null,
6571

6672
startPolling: function() {
73+
if (this.isPolling()) {
74+
return;
75+
}
76+
this.setPolling(true);
77+
6778
this.getNode().getStatus().getProgressSequence()
6879
.resetSequence();
6980

@@ -146,10 +157,12 @@ qx.Class.define("osparc.data.model.IframeHandler", {
146157
__nodeState: function(starting=true) {
147158
// Check if study is still there
148159
if (this.getStudy() === null || this.__stopRequestingStatus === true) {
160+
this.setPolling(false);
149161
return;
150162
}
151163
// Check if node is still there
152164
if (this.getStudy().getWorkbench().getNode(this.getNode().getNodeId()) === null) {
165+
this.setPolling(false);
153166
return;
154167
}
155168

@@ -176,6 +189,7 @@ qx.Class.define("osparc.data.model.IframeHandler", {
176189
};
177190
node.fireDataEvent("showInLogger", errorMsgData);
178191
if ("status" in err && err.status === 406) {
192+
this.setPolling(false);
179193
return;
180194
}
181195
if (this.__unresponsiveRetries > 0) {
@@ -190,6 +204,7 @@ qx.Class.define("osparc.data.model.IframeHandler", {
190204
const interval = Math.floor(Math.random() * 5000) + 3000;
191205
setTimeout(() => this.__nodeState(), interval);
192206
} else {
207+
this.setPolling(false);
193208
node.getStatus().setInteractive("failed");
194209
osparc.FlashMessenger.getInstance().logAs(this.tr("There was an error starting") + " " + node.getLabel(), "ERROR");
195210
}
@@ -201,14 +216,17 @@ qx.Class.define("osparc.data.model.IframeHandler", {
201216
const nodeId = data["service_uuid"];
202217
const node = this.getNode();
203218
const status = node.getStatus();
219+
let nextPollIn = null;
220+
let pollingInNextStage = null;
204221
switch (serviceState) {
205222
case "idle": {
206223
status.setInteractive(serviceState);
207224
if (starting && this.__unresponsiveRetries>0) {
208225
// a bit of a hack. We will get rid of it when the backend pushes the states
209226
this.__unresponsiveRetries--;
210-
const interval = 2000;
211-
qx.event.Timer.once(() => this.__nodeState(starting), this, interval);
227+
nextPollIn = 2000;
228+
} else {
229+
this.setPolling(false);
212230
}
213231
break;
214232
}
@@ -228,27 +246,24 @@ qx.Class.define("osparc.data.model.IframeHandler", {
228246
node.fireDataEvent("showInLogger", msgData);
229247
}
230248
status.setInteractive(serviceState);
231-
const interval = 10000;
232-
qx.event.Timer.once(() => this.__nodeState(starting), this, interval);
249+
nextPollIn = 10000;
233250
break;
234251
}
235252
case "stopping":
236253
case "unknown":
237254
case "starting":
238255
case "pulling": {
239256
status.setInteractive(serviceState);
240-
const interval = 5000;
241-
qx.event.Timer.once(() => this.__nodeState(starting), this, interval);
257+
nextPollIn = 5000;
242258
break;
243259
}
244260
case "running": {
245261
if (nodeId !== node.getNodeId()) {
246-
return;
262+
break;
247263
}
248264
if (!starting) {
249265
status.setInteractive("stopping");
250-
const interval = 5000;
251-
qx.event.Timer.once(() => this.__nodeState(starting), this, interval);
266+
nextPollIn = 5000;
252267
break;
253268
}
254269
const {
@@ -260,6 +275,7 @@ qx.Class.define("osparc.data.model.IframeHandler", {
260275
this.__retriesLeft = 40;
261276
this.__waitForServiceReady(srvUrl);
262277
}
278+
pollingInNextStage = true;
263279
break;
264280
}
265281
case "complete":
@@ -279,12 +295,18 @@ qx.Class.define("osparc.data.model.IframeHandler", {
279295
console.error(serviceState, "service state not supported");
280296
break;
281297
}
298+
if (nextPollIn) {
299+
qx.event.Timer.once(() => this.__nodeState(starting), this, nextPollIn);
300+
} else if (pollingInNextStage !== true) {
301+
this.setPolling(false);
302+
}
282303
},
283304

284305
__waitForServiceReady: function(srvUrl) {
285306
this.getNode().getStatus().setInteractive("connecting");
286307

287308
if (this.__retriesLeft === 0) {
309+
this.setPolling(false);
288310
return;
289311
}
290312

@@ -293,6 +315,7 @@ qx.Class.define("osparc.data.model.IframeHandler", {
293315

294316
// Check if node is still there
295317
if (this.getStudy().getWorkbench().getNode(this.getNode().getNodeId()) === null) {
318+
this.setPolling(false);
296319
return;
297320
}
298321
const interval = 5000;
@@ -310,6 +333,7 @@ qx.Class.define("osparc.data.model.IframeHandler", {
310333
console.log("Connecting: fetch's response status", response.status);
311334
}
312335
if (response.status < 400) {
336+
this.setPolling(false);
313337
this.__serviceReadyIn(srvUrl);
314338
} else {
315339
console.log(`Connecting: ${srvUrl} is not reachable. Status: ${response.status}`);

services/static-webserver/client/source/class/osparc/desktop/WorkbenchView.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -725,10 +725,9 @@ qx.Class.define("osparc.desktop.WorkbenchView", {
725725
widget.addListener("restore", () => this.setMaximized(false), this);
726726
}
727727
});
728-
this.__iFrameChanged(node);
729-
730728
node.getIframeHandler().addListener("iframeChanged", () => this.__iFrameChanged(node), this);
731729
iFrame.addListener("load", () => this.__iFrameChanged(node), this);
730+
this.__iFrameChanged(node);
732731
} else {
733732
// This will keep what comes after at the bottom
734733
this.__iframePage.add(new qx.ui.core.Spacer(), {

services/static-webserver/client/source/class/osparc/node/NodeView.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,10 @@ qx.Class.define("osparc.node.NodeView", {
7474
const loadingPage = this.getNode().getLoadingPage();
7575
const iFrame = this.getNode().getIFrame();
7676
if (loadingPage && iFrame) {
77-
this.__iFrameChanged();
77+
const node = this.getNode();
78+
node.getIframeHandler().addListener("iframeChanged", () => this.__iFrameChanged(), this);
7879
iFrame.addListener("load", () => this.__iFrameChanged());
80+
this.__iFrameChanged();
7981
} else {
8082
// This will keep what comes after at the bottom
8183
this._iFrameLayout.add(new qx.ui.core.Spacer(), {
@@ -150,8 +152,10 @@ qx.Class.define("osparc.node.NodeView", {
150152
__iFrameChanged: function() {
151153
this._iFrameLayout.removeAll();
152154

153-
const loadingPage = this.getNode().getLoadingPage();
154-
const iFrame = this.getNode().getIFrame();
155+
const node = this.getNode();
156+
157+
const loadingPage = node.getLoadingPage();
158+
const iFrame = node.getIFrame();
155159
const src = iFrame.getSource();
156160
const iFrameView = (src === null || src === "about:blank") ? loadingPage : iFrame;
157161
this._iFrameLayout.add(iFrameView, {

services/static-webserver/client/source/class/osparc/viewer/NodeViewer.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,9 @@ qx.Class.define("osparc.viewer.NodeViewer", {
5151
const iframeHandler = node.getIframeHandler();
5252
if (iframeHandler) {
5353
iframeHandler.startPolling();
54-
iframeHandler.addListener("iframeChanged", () => this.__buildLayout(), this);
55-
iframeHandler.getIFrame().addListener("load", () => this.__buildLayout(), this);
56-
this.__buildLayout();
54+
iframeHandler.addListener("iframeChanged", () => this.__iFrameChanged(), this);
55+
iframeHandler.getIFrame().addListener("load", () => this.__iFrameChanged(), this);
56+
this.__iFrameChanged();
5757

5858
this.__attachSocketEventHandlers();
5959
}
@@ -89,10 +89,11 @@ qx.Class.define("osparc.viewer.NodeViewer", {
8989
},
9090

9191
members: {
92-
__buildLayout: function() {
92+
__iFrameChanged: function() {
9393
this._removeAll();
9494

9595
const iframeHandler = this.getNode().getIframeHandler();
96+
9697
const loadingPage = iframeHandler.getLoadingPage();
9798
const iFrame = iframeHandler.getIFrame();
9899
const src = iFrame.getSource();

0 commit comments

Comments
 (0)