From 8a9fd209deb3f214f434ea223a899d5770cdb94a Mon Sep 17 00:00:00 2001 From: Ashton South Date: Tue, 4 Jun 2024 14:06:41 -0400 Subject: [PATCH] refractor systemstatus polling (#3587) --- .../dashboard/app/javascript/system_status.js | 22 +++++-------------- 1 file changed, 5 insertions(+), 17 deletions(-) diff --git a/apps/dashboard/app/javascript/system_status.js b/apps/dashboard/app/javascript/system_status.js index d3c634b849..823b125c3b 100644 --- a/apps/dashboard/app/javascript/system_status.js +++ b/apps/dashboard/app/javascript/system_status.js @@ -1,19 +1,7 @@ import { statusIndexUrl } from './config' -import { replaceHTML } from './turbo_shim' +import { pollAndReplace } from './turbo_shim' -function poll() { - pollDelay = 30000; // Probably want a configuration in the future, but 30 seconds for now - - url = statusIndexUrl(); - fetch(url, { headers: { Accept: "text/vnd.turbo-stream.html" } }) - .then(response => response.ok ? Promise.resolve(response) : Promise.reject(response.text())) - .then((r) => r.text()) - .then((html) => replaceHTML("system-status", html)) - .then(setTimeout(poll, pollDelay)) - .catch((err) => { - console.log('Cannot retrieve system status information due to error:'); - console.log(err); - }); -} - -jQuery(poll) \ No newline at end of file +jQuery(() => { + pollDelay = 30000; + pollAndReplace(statusIndexUrl(), pollDelay, "system-status"); +}) \ No newline at end of file