2936: improve progress bar for failed jobs
authorTim Pierce <twp@curoverse.com>
Tue, 17 Jun 2014 13:57:00 +0000 (09:57 -0400)
committerTim Pierce <twp@curoverse.com>
Tue, 17 Jun 2014 13:57:00 +0000 (09:57 -0400)
Ensure that:

* All job progress bars reflect at least one task.  If a job has no
  tasks at all (done, failed, finished, or todo) that should be
  considered a failed job, so render a progress bar as though one task
  ran and failed.

* A failed job (j[:success] == false) always shows at least one failed
  task.  If a job is marked as failed but has no failed tasks, then
  pretend there was one failed task so at least some red will appear in
  the progress bar.

Fixes #2936.

apps/workbench/app/views/application/_job_progress.html.erb

index a25acc3a048b29e31fe8020c880e88b534cd76f8..d25babae6db7e424ed69636da27b9ca7208aaf02 100644 (file)
@@ -1,4 +1,17 @@
-<% percent_total_tasks = 100 / (j[:tasks_summary][:done] + j[:tasks_summary][:running] + j[:tasks_summary][:failed] + j[:tasks_summary][:todo]) rescue 0 %>
+<% failed = j[:tasks_summary][:failed] rescue 0 %>
+<% done = j[:tasks_summary][:done] rescue 0 %>
+<% running = j[:tasks_summary][:running] rescue 0 %>
+<% todo = j[:tasks_summary][:todo] rescue 0 %>
+
+<% if j[:success] == false and failed == 0 %>
+  <% failed = 1 # job failed, so show as though at least one task failed %>
+<% else %>
+
+<% if done + running + failed + todo == 0 %>
+  <% failed = 1 # no tasks ran; show as though one task ran and failed %>
+<% end %>
+
+<% percent_total_tasks = 100 / (done + running + failed + todo) %>
 
 <% if defined? scaleby %>
   <% percent_total_tasks *= scaleby %>
   <div class="progress">
 <% end %>
 
-<span class="progress-bar progress-bar-success" style="width: <%= j[:tasks_summary][:done] * percent_total_tasks rescue 0 %>%;">
+<span class="progress-bar progress-bar-success" style="width: <%= done * percent_total_tasks %>%;">
 </span>
-<span class="progress-bar progress-bar-danger" style="width: <%= j[:tasks_summary][:failed] * percent_total_tasks rescue 0 %>%;">
+<span class="progress-bar progress-bar-danger" style="width: <%= failed * percent_total_tasks %>%;">
 </span>
-<span class="progress-bar" style="width: <%= j[:tasks_summary][:running] * percent_total_tasks rescue 0 %>%;">
+<span class="progress-bar" style="width: <%= running * percent_total_tasks %>%;">
 </span>
 
 <% if not defined? scaleby %>