From 4e8745c2a744a2c3e6b44ee6100fb1a26749cebf Mon Sep 17 00:00:00 2001 From: Peter Amstutz Date: Thu, 25 Sep 2014 20:41:41 -0400 Subject: [PATCH] 3899: Set :state in pipeline_instance_helper.rb and remove Job::state. --- .../app/helpers/pipeline_instances_helper.rb | 13 +++++++++++ apps/workbench/app/models/job.rb | 23 ------------------- .../application/_job_status_label.html.erb | 3 +-- .../_running_component.html.erb | 6 ++--- .../views/projects/_show_dashboard.html.erb | 8 +++---- 5 files changed, 21 insertions(+), 32 deletions(-) diff --git a/apps/workbench/app/helpers/pipeline_instances_helper.rb b/apps/workbench/app/helpers/pipeline_instances_helper.rb index ca48306242..78f491a85c 100644 --- a/apps/workbench/app/helpers/pipeline_instances_helper.rb +++ b/apps/workbench/app/helpers/pipeline_instances_helper.rb @@ -104,6 +104,19 @@ module PipelineInstancesHelper pj[:job] = job[c[:job][:uuid]] else pj[:job] = c[:job].is_a?(Hash) ? c[:job] : {} + + # Figure out the state based on the other fields. + pj[:job][:state] = if pj[:job][:cancelled_at] + "Cancelled" + elsif pj[:job][:success] == false + "Failed" + elsif pj[:job][:success] == true + "Complete" + elsif pj[:job][:running] == true + "Running" + else + "Queued" + end end pj[:percent_done] = 0 pj[:percent_running] = 0 diff --git a/apps/workbench/app/models/job.rb b/apps/workbench/app/models/job.rb index f933c07701..977eef91bf 100644 --- a/apps/workbench/app/models/job.rb +++ b/apps/workbench/app/models/job.rb @@ -46,29 +46,6 @@ class Job < ArvadosBase arvados_api_client.unpack_api_response arvados_api_client.api("jobs/", "queue", {"_method"=> "GET"}) end - # The 'job' parameter can be either a Job model object, or a hash containing - # the same fields as a Job object (such as the :job entry of a pipeline - # component). - def self.state job - # This has a valid state method on it so call that - if job.respond_to? :state and job.state - return job.state - end - - # Figure out the state based on the other fields. - if job[:cancelled_at] - "Cancelled" - elsif job[:success] == false - "Failed" - elsif job[:success] == true - "Complete" - elsif job[:running] == true - "Running" - else - "Queued" - end - end - def textile_attributes [ 'description' ] end diff --git a/apps/workbench/app/views/application/_job_status_label.html.erb b/apps/workbench/app/views/application/_job_status_label.html.erb index 0d012dbd30..17073fe98c 100644 --- a/apps/workbench/app/views/application/_job_status_label.html.erb +++ b/apps/workbench/app/views/application/_job_status_label.html.erb @@ -1,4 +1,3 @@ -<% status = Job::state j %> <% to_label = { "Cancelled" => "danger", "Complete" => "success", @@ -8,4 +7,4 @@ nil => "default" } %> - <%= if defined? title then title else status.downcase end %> + <%= if defined? title then title else j[:state].downcase end %> diff --git a/apps/workbench/app/views/pipeline_instances/_running_component.html.erb b/apps/workbench/app/views/pipeline_instances/_running_component.html.erb index be3aba81b9..8613d54a10 100644 --- a/apps/workbench/app/views/pipeline_instances/_running_component.html.erb +++ b/apps/workbench/app/views/pipeline_instances/_running_component.html.erb @@ -31,7 +31,7 @@ <% end %> - <% if Job::state(current_job).in? ["Complete", "Failed", "Cancelled"] %> + <% if current_job[:state].in? ["Complete", "Failed", "Cancelled"] %>
<% if pj[:output_uuid] %> <%= link_to_if_arvados_object pj[:output_uuid], friendly_name: true %> @@ -41,7 +41,7 @@ No output. <% end %>
- <% elsif Job::state(current_job) == "Running" %> + <% elsif current_job[:state] == "Running" %>
<%= pj[:progress_bar] %>
@@ -51,7 +51,7 @@ <%= button_tag "Cancel", {class: 'btn btn-xs btn-danger', id: "cancel-job-button"} %> <% end %> - <% elsif Job::state(current_job) == "Queued" %> + <% elsif current_job[:state] == "Queued" %>
<% queuetime = Time.now - current_job[:created_at] %> Queued for <%= render_runtime(queuetime, true) %>. diff --git a/apps/workbench/app/views/projects/_show_dashboard.html.erb b/apps/workbench/app/views/projects/_show_dashboard.html.erb index 2841637ded..d802825440 100644 --- a/apps/workbench/app/views/projects/_show_dashboard.html.erb +++ b/apps/workbench/app/views/projects/_show_dashboard.html.erb @@ -34,13 +34,13 @@ <% queued = [] %> <% p.components.each do |k, v| %> <% if v.is_a? Hash and v[:job] %> - <% if Job::state(v[:job]) == "Running" %> + <% if v[:job][:state] == "Running" %> <% running << k %> - <% elsif Job::state(v[:job]) == "Failed" or Job::state(v[:job]) == "Cancelled" %> + <% elsif v[:job][:state] == "Failed" or v[:job][:state] == "Cancelled" %> <% failed << k %> - <% elsif Job::state(v[:job]) == "Complete" %> + <% elsif v[:job][:state] == "Complete" %> <% completed << k %> - <% elsif Job::state(v[:job]) == "Queued" %> + <% elsif v[:job][:state] == "Queued" %> <% queued << k %> <% end %> <% end %> -- 2.39.5