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

SW-1939 fix healthcheck endpoint (#1634) #1641

Open
wants to merge 1 commit into
base: alpha
Choose a base branch
from
Open
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
28 changes: 16 additions & 12 deletions octoprint_mrbeam/static/js/app/view-models/material-store.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ $(function () {

window.mrbeam.viewModels["materialStoreViewModel"] = self;
self.material_store_iframe_src = "";
self.healthcheck_url = "";

self.initialiseStore = function (healthcheck_url, url) {
if (
Expand All @@ -25,13 +26,13 @@ $(function () {
);
}

$.ajax({
url: healthcheck_url,
method: "HEAD",
timeout: 6000,
success: self.loadMaterialStore,
error: self.showConnectionError,
});
if (healthcheck_url !== self.healthcheck_url) {
self.healthcheck_url = healthcheck_url;
}

fetch(self.healthcheck_url)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the fetch timeouts at 300 seonds on default, would it be better to limit it to a lower value?
https://dmitripavlutin.com/timeout-fetch-request/

.then(self.loadMaterialStore)
.catch(self.showConnectionError);
} else {
self.showConnectionError();
}
Expand Down Expand Up @@ -70,14 +71,17 @@ $(function () {
};

self.sendMessageToMaterialStoreIframe = function (event, payload) {
let materialStoreIframeElement = $("#material_store_iframe");
let data = {
const materialStoreIframe = document.getElementById('material_store_iframe');
// IE patch although we don't officially support it
const iframeContentWindow = materialStoreIframe.contentWindow ? materialStoreIframe.contentWindow : materialStoreIframe.contentDocument.defaultView;

const data = {
event: event,
payload: payload,
};

if (materialStoreIframeElement.contentWindow) {
materialStoreIframeElement.contentWindow.postMessage(
if (iframeContentWindow) {
iframeContentWindow.postMessage(
data,
self.material_store_iframe_src
);
Expand All @@ -91,7 +95,7 @@ $(function () {
$("#material_store_iframe").attr("src", self.material_store_iframe_src);
$("#material_store_iframe").on("load", self.onLoadMaterialStore);
$("#refresh_material_store_btn").click(() =>
self.initialiseStore(self.material_store_iframe_src)
self.initialiseStore(self.healthcheck_url, self.material_store_iframe_src)
);
}

Expand Down