From 4aabe7a5149eff71d07dc30c711f7df6341a5f58 Mon Sep 17 00:00:00 2001 From: Jeff Ohrstrom Date: Tue, 27 Aug 2024 13:43:02 -0400 Subject: [PATCH 1/3] dont requery for completed jobs --- apps/dashboard/app/javascript/projects.js | 19 +++++++++++++++---- .../projects/_job_details.turbo_stream.erb | 2 +- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/apps/dashboard/app/javascript/projects.js b/apps/dashboard/app/javascript/projects.js index a4e13866ef..a154420881 100644 --- a/apps/dashboard/app/javascript/projects.js +++ b/apps/dashboard/app/javascript/projects.js @@ -36,27 +36,38 @@ function pollForJobInfo(element) { // html open as well. const currentData = element.querySelector(`#${element.id}_data`); let currentlyOpen = false; + const responseElement = stringToHtml(html); if(currentData != null) { currentlyOpen = currentData.classList.contains('show'); } + // if it's currently open keep it open. if(currentlyOpen) { - const responseElement = new DOMParser().parseFromString(html, "text/xml"); const dataDiv = responseElement.querySelector(`#${element.id}_data`); dataDiv.classList.add('show'); - html = (new XMLSerializer()).serializeToString(responseElement); } - replaceHTML(element.id, html) + const jobStatus = responseElement.dataset['jobStatus']; + replaceHTML(element.id, responseElement.outerHTML); + return jobStatus; + }) + .then((status) => { + if(status != 'completed') { + setTimeout(pollForJobInfo, 30000, element); + } }) - .then(setTimeout(pollForJobInfo, 30000, element)) .catch((err) => { console.log('Cannot not retrive job details due to error:'); console.log(err); }); } +function stringToHtml(html) { + const template = document.createElement('template'); + template.innerHTML = html.trim(); + return template.content.firstChild; +} function updateProjectSize(element) { diff --git a/apps/dashboard/app/views/projects/_job_details.turbo_stream.erb b/apps/dashboard/app/views/projects/_job_details.turbo_stream.erb index 30d7bb1fb3..7711147da5 100644 --- a/apps/dashboard/app/views/projects/_job_details.turbo_stream.erb +++ b/apps/dashboard/app/views/projects/_job_details.turbo_stream.erb @@ -3,7 +3,7 @@ id = "job_#{job.cluster}_#{job.id}" -%> - + diff --git a/apps/dashboard/app/views/projects/_job_details_content.html.erb b/apps/dashboard/app/views/projects/_job_details_content.html.erb new file mode 100644 index 0000000000..44163aad77 --- /dev/null +++ b/apps/dashboard/app/views/projects/_job_details_content.html.erb @@ -0,0 +1,24 @@ + +<%- + id = "job_#{job.cluster}_#{job.id}" +-%> + +
+ +
+
+ + <% job.to_human_display.each do |name, value| %> + + + + + <% end %> +
<%= name %><%= value %>
+
+
+
diff --git a/apps/dashboard/app/views/projects/show.html.erb b/apps/dashboard/app/views/projects/show.html.erb index a12951f845..b44b9fc472 100644 --- a/apps/dashboard/app/views/projects/show.html.erb +++ b/apps/dashboard/app/views/projects/show.html.erb @@ -59,12 +59,14 @@

Active Jobs

- <%= render(partial: 'job_details', collection: @project.jobs, as: :job) %> + <%= render(partial: 'job_details', collection: @project.active_jobs, as: :job) %>

Completed Jobs

-
+
+ <%= render(partial: 'job_details_content', collection: @project.completed_jobs, as: :job) %> +