Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 [Frontend] Fix: From service running to connect to iframe #5987

Merged
merged 7 commits into from
Jun 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,7 @@ qx.Class.define("osparc.data.model.Node", {
__posY: null,
__unresponsiveRetries: null,
__stopRequestingStatus: null,
__retriesLeft: null,

getWorkbench: function() {
return this.getStudy().getWorkbench();
Expand Down Expand Up @@ -1245,6 +1246,7 @@ qx.Class.define("osparc.data.model.Node", {
} = osparc.utils.Utils.computeServiceUrl(data);
this.setDynamicV2(isDynamicV2);
if (srvUrl) {
this.__retriesLeft = 40;
this.__waitForServiceReady(srvUrl);
}
break;
Expand Down Expand Up @@ -1327,68 +1329,49 @@ qx.Class.define("osparc.data.model.Node", {
}
},

__waitForServiceReady: async function(srvUrl) {
__waitForServiceReady: function(srvUrl) {
this.getStatus().setInteractive("connecting");

if (this.__retriesLeft === 0) {
return;
}

const retry = () => {
this.__retriesLeft--;

// Check if node is still there
if (this.getWorkbench().getNode(this.getNodeId()) === null) {
return;
}
const interval = 3000;
const interval = 5000;
qx.event.Timer.once(() => this.__waitForServiceReady(srvUrl), this, interval);
};

// ping for some time until it is really reachable
try {
if (osparc.utils.Utils.isDevelopmentPlatform()) {
console.log("Connecting: about to fetch ", srvUrl);
}
const response = await fetch(srvUrl);
if (osparc.utils.Utils.isDevelopmentPlatform()) {
console.log("Connecting: fetch's response ", JSON.stringify(response));
console.log("Connecting: about to fetch", srvUrl);
}
if (response.ok || response.status === 302) {
// ok = status in the range 200-299
// some services might respond with a 302 which is also fine
// instead of
// - requesting its frontend to make sure it is ready and ...
// - waiting for the "load" event triggered by the content of the iframe
// we will skip those steps and directly switch its iframe
this.__serviceReadyIn(srvUrl);
} else {
console.log(`Connecting: ${srvUrl} is not reachable. Status: ${response.status}`);
retry();
}
} catch (error) {
console.error(`Connecting: Error while checking ${srvUrl}:`, error);
retry();
}
},

__waitForServiceWebsite: function(srvUrl) {
// request the frontend to make sure it is ready
let retries = 5
const openAndSend = () => {
if (retries === 0) {
return
}
retries--
fetch(srvUrl)
.then(request => {
if (request.status >= 200 || request.status < 300) {
this.__serviceReadyIn(srvUrl)
.then(response => {
if (osparc.utils.Utils.isDevelopmentPlatform()) {
console.log("Connecting: fetch's response status", response.status);
}
if (response.status < 400) {
this.__serviceReadyIn(srvUrl);
} else {
retry() // eslint-disable-line no-use-before-define
console.log(`Connecting: ${srvUrl} is not reachable. Status: ${response.status}`);
retry();
}
})
.catch(() => {
retry() // eslint-disable-line no-use-before-define
})
.catch(err => {
console.error("Connecting: Error", err);
retry();
});
} catch (error) {
console.error(`Connecting: Error while checking ${srvUrl}:`, error);
retry();
}
const retry = () => {
setTimeout(() => openAndSend(), 2000)
};
openAndSend()
},

__serviceReadyIn: function(srvUrl) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,8 @@ qx.Class.define("osparc.info.MergedLarge", {
})
.catch(err => {
console.error(err);
osparc.FlashMessenger.getInstance().logAs(this.tr("There was an error while updating the information."), "ERROR");
const msg = err.message || this.tr("There was an error while updating the information.");
osparc.FlashMessenger.getInstance().logAs(msg, "ERROR");
});
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,8 @@ qx.Class.define("osparc.info.ServiceLarge", {
})
.catch(err => {
console.error(err);
osparc.FlashMessenger.getInstance().logAs(this.tr("There was an error while updating the information."), "ERROR");
const msg = err.message || this.tr("There was an error while updating the information.");
osparc.FlashMessenger.getInstance().logAs(msg, "ERROR");
});
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,8 @@ qx.Class.define("osparc.info.StudyLarge", {
})
.catch(err => {
console.error(err);
osparc.FlashMessenger.getInstance().logAs(this.tr("There was an error while updating the information."), "ERROR");
const msg = err.message || this.tr("There was an error while updating the information.");
osparc.FlashMessenger.getInstance().logAs(msg, "ERROR");
});
}
}
Expand Down
Loading