[ARVADOS] updated: d1d4aba8c3eb7e3b605639a4b02cb9d26c033ad2

Git user git at public.curoverse.com
Sat Jun 4 10:07:47 EDT 2016


Summary of changes:
 apps/workbench/app/models/job_work_unit.rb         |  28 -----
 apps/workbench/app/models/proxy_work_unit.rb       | 132 +++++++++++++++++++++
 apps/workbench/app/models/work_unit.rb             |  49 ++++++++
 .../app/views/work_unit/_component_detail.html.erb |   2 +-
 .../app/views/work_unit/_progress.html.erb         |   2 +-
 .../app/views/work_unit/_show_child.html.erb       |  54 +++------
 .../app/views/work_unit/_show_component.html.erb   |  50 +++-----
 7 files changed, 216 insertions(+), 101 deletions(-)

       via  d1d4aba8c3eb7e3b605639a4b02cb9d26c033ad2 (commit)
      from  3d60a5dcfb6765b223d224dda3980226230464d0 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.


commit d1d4aba8c3eb7e3b605639a4b02cb9d26c033ad2
Author: radhika <radhika at curoverse.com>
Date:   Sat Jun 4 10:06:09 2016 -0400

    8876: introduce view helper methods such as link_to_log and queuedtime etc so that the views do not have to do too many decisions based on the state of the work unit.

diff --git a/apps/workbench/app/models/job_work_unit.rb b/apps/workbench/app/models/job_work_unit.rb
index 80dea19..49f490d 100644
--- a/apps/workbench/app/models/job_work_unit.rb
+++ b/apps/workbench/app/models/job_work_unit.rb
@@ -23,34 +23,6 @@ class JobWorkUnit < ProxyWorkUnit
     self.my_children = items
   end
 
-  def parameters
-    get(:script_parameters)
-  end
-
-  def repository
-    get(:repository)
-  end
-
-  def script
-    get(:script)
-  end
-
-  def script_version
-    get(:script_version)
-  end
-
-  def supplied_script_version
-    get(:supplied_script_version)
-  end
-
-  def docker_image
-    get(:docker_image_locator)
-  end
-
-  def nondeterministic
-    get(:nondeterministic)
-  end
-
   def child_summary
     if children.any?
       super
diff --git a/apps/workbench/app/models/proxy_work_unit.rb b/apps/workbench/app/models/proxy_work_unit.rb
index 1a24cd5..0fb2607 100644
--- a/apps/workbench/app/models/proxy_work_unit.rb
+++ b/apps/workbench/app/models/proxy_work_unit.rb
@@ -145,6 +145,34 @@ class ProxyWorkUnit < WorkUnit
     end
   end
 
+  def parameters
+    get(:script_parameters)
+  end
+
+  def repository
+    get(:repository)
+  end
+
+  def script
+    get(:script)
+  end
+
+  def script_version
+    get(:script_version)
+  end
+
+  def supplied_script_version
+    get(:supplied_script_version)
+  end
+
+  def docker_image
+    get(:docker_image_locator)
+  end
+
+  def nondeterministic
+    get(:nondeterministic)
+  end
+
   def runtime_constraints
     get(:runtime_constraints)
   end
@@ -178,6 +206,110 @@ class ProxyWorkUnit < WorkUnit
     resource_class.where(uuid: [uuid]).first rescue nil
   end
 
+  def link_to_log
+    if state_label.in? ["Complete", "Failed", "Cancelled"]
+      lc = log_collection
+      if lc
+        logCollection = Collection.find? lc
+        if logCollection
+          ApplicationController.helpers.link_to("Log", "#{uri}#Log")
+        else
+          "Log unavailable"
+        end
+      end
+    elsif state_label == "Running"
+      if readable?
+        ApplicationController.helpers.link_to("Log", "#{uri}#Log")
+      else
+        "Log unavailable"
+      end
+    else
+      ""
+    end
+  end
+
+  def walltime
+    if state_label != "Queued"
+      if started_at
+        ((if finished_at then finished_at else Time.now() end) - started_at)
+      end
+    end
+  end
+
+  def cputime
+    if state_label != "Queued"
+      if started_at
+        (runtime_constraints.andand[:min_nodes] || 1) *
+             ((finished_at || Time.now()) - started_at)
+      end
+    end
+  end
+
+  def queuedtime
+    if state_label == "Queued"
+      Time.now - Time.parse(created_at.to_s)
+    end
+  end
+
+  def show_child_summary
+    if state_label == "Running"
+      if child_summary
+        child_summary_str
+      end
+    end
+  end
+
+  def is_running?
+    state_label == 'Running'
+  end
+
+  def is_paused?
+    state_label == 'Paused'
+  end
+
+  def is_finished?
+    state_label.in? ["Complete", "Failed", "Cancelled"]
+  end
+
+  def is_failed?
+    state_label == 'Failed'
+  end
+
+  def can_be_canceled?
+    state_label.in? ["Queued", "Running"] and can_cancel?
+  end
+
+  def ran_for_str
+    ran_for = nil
+    if state_label
+      ran_for = "It "
+      if state_label == 'Running'
+        ran_for << "has run"
+      else
+        ran_for << "ran"
+      end
+      ran_for << " for"
+    end
+    ran_for
+  end
+
+  def started_and_active_for_str
+    active_for = nil
+
+    if started_at
+      active_for_1 = "This #{title} started at "
+      active_for_2 = "It "
+      if state_label == 'Complete'
+        active_for_2 << "completed in "
+      elsif state_label == 'Failed'
+        active_for_2 << "failed after "
+      else
+        active_for_2 << "has been active for "
+      end
+      [active_for_1, active_for_2]
+    end
+  end
+
   protected
 
   def get key
diff --git a/apps/workbench/app/models/work_unit.rb b/apps/workbench/app/models/work_unit.rb
index fba9015..5328953 100644
--- a/apps/workbench/app/models/work_unit.rb
+++ b/apps/workbench/app/models/work_unit.rb
@@ -118,4 +118,53 @@ class WorkUnit
   def has_unreadable_children
     # accept it if you can't understand your own children
   end
+
+  # view helper methods
+  def link_to_log
+    # display a link to log if present
+  end
+
+  def walltime
+    # return walltime for a running or completed work unit
+  end
+
+  def cputime
+    # return cputime for a running or completed work unit
+  end
+
+  def queuedtime
+    # return queued time if the work unit is queued
+  end
+
+  def show_child_summary
+    # child summary for a running work unit
+  end
+
+  def is_running?
+    # is the work unit in running state?
+  end
+
+  def is_paused?
+    # is the work unit in paused state?
+  end
+
+  def is_finished?
+    # is the work unit in finished state?
+  end
+
+  def is_failed?
+    # is this work unit in failed state?
+  end
+
+  def can_be_canceled?
+    # true if work unit is in queued or running states and supports can_cancel?
+  end
+
+  def ran_for_str
+    # display string for how long it has run
+  end
+
+  def started_and_active_for_str
+    # display string for how long it has been active
+  end
 end
diff --git a/apps/workbench/app/views/work_unit/_component_detail.html.erb b/apps/workbench/app/views/work_unit/_component_detail.html.erb
index 6f06825..38e1b5b 100644
--- a/apps/workbench/app/views/work_unit/_component_detail.html.erb
+++ b/apps/workbench/app/views/work_unit/_component_detail.html.erb
@@ -28,8 +28,8 @@
                 </tr>
                 <% end %>
               <% end %>
-            <% end %>
             </table>
+            <% end %>
           </div>
           <div class="col-md-6">
             <table>
diff --git a/apps/workbench/app/views/work_unit/_progress.html.erb b/apps/workbench/app/views/work_unit/_progress.html.erb
index ef7dcd9..e06bad6 100644
--- a/apps/workbench/app/views/work_unit/_progress.html.erb
+++ b/apps/workbench/app/views/work_unit/_progress.html.erb
@@ -1,4 +1,4 @@
-<% if wu.state_label == 'Running' %>
+<% if wu.is_running? %>
   <% if @object.uuid == wu.uuid and wu.progress == 0.0 %>
     <span class="label label-<%= wu.state_bootstrap_class %>"> Active </span>
   <% else%>
diff --git a/apps/workbench/app/views/work_unit/_show_child.html.erb b/apps/workbench/app/views/work_unit/_show_child.html.erb
index 64881a1..70e48cb 100644
--- a/apps/workbench/app/views/work_unit/_show_child.html.erb
+++ b/apps/workbench/app/views/work_unit/_show_child.html.erb
@@ -21,60 +21,36 @@
           <div class="col-md-8"></div>
         <% else %>
           <div class="col-md-1">
-              <% if current_obj.state_label.in? ["Complete", "Failed", "Cancelled"] %>
-                <% if current_obj.log_collection %>
-                  <% logCollection = Collection.find? current_obj.log_collection %>
-                  <% if logCollection %>
-                    <%= link_to "Log", "#{current_obj.uri}#Log" %>
-                  <% else %>
-                    Log unavailable
-                  <% end %>
-                <% end %>
-              <% elsif current_obj.state_label == "Running" %>
-                <% if current_obj.readable? %>
-                  <%= link_to "Log", "#{current_obj.uri}#Log" %>
-                <% else %>
-                  Log unavailable
-                <% end %>
-              <% end %>
+            <%= current_obj.link_to_log %>
           </div>
 
           <%# column offset 5 %>
-          <% if current_obj.state_label != "Queued" %>
+          <% walltime = current_obj.walltime %>
+          <% cputime = current_obj.cputime %>
+          <% if walltime and cputime %>
           <div class="col-md-3">
-            <% if current_obj.started_at %>
-              <% walltime = ((if current_obj.finished_at then current_obj.finished_at else Time.now() end) - current_obj.started_at) %>
-              <% cputime = (current_obj.runtime_constraints.andand[:min_nodes] || 1) *
-                           ((current_obj.finished_at || Time.now()) - current_obj.started_at) %>
               <%= render_runtime(walltime, false) %>
               <% if cputime > 0 %> / <%= render_runtime(cputime, false) %> (<%= (cputime/walltime).round(1) %>⨯)<% end %>
-            <% end %>
           </div>
           <% end %>
 
-          <% if current_obj.state_label == "Queued" %>
+          <% queuetime = current_obj.queuedtime %>
+          <% if queuetime %>
             <%# column offset 5 %>
             <div class="col-md-6">
-              <% queuetime = Time.now - Time.parse(current_obj.created_at.to_s) %>
               Queued for <%= render_runtime(queuetime, false) %>.
             </div>
-          <% elsif current_obj.state_label == "Running" %>
-            <% if current_obj.child_summary %>
-              <%# column offset 8 %>
-              <div class="col-md-3">
-                <span class="task-summary-status">
-                  <% if current_obj.child_summary_str %>
-                    <%= current_obj.child_summary_str %>
-                  <% end %>
-                </span>
-              </div>
-            <% end %>
-          <% elsif current_obj.state_label.in? ["Complete", "Failed", "Cancelled"] %>
+          <% elsif current_obj.show_child_summary %>
+            <%# column offset 8 %>
+            <div class="col-md-3">
+              <span class="task-summary-status">
+                <%= current_obj.child_summary_str %>
+              </span>
+            </div>
+          <% elsif current_obj.is_finished? %>
             <%# column offset 8 %>
             <div class="col-md-4 text-overflow-ellipsis">
               <% if current_obj.output %>
-                <%= link_to_arvados_object_if_readable(current_obj.output, 'Output data not available', friendly_name: true) %>
-              <% elsif current_obj.output %>
                 <%= link_to_arvados_object_if_readable(current_obj.output, 'Output data not available', link_text: "Output of #{current_obj.label}") %>
               <% else %>
                 No output.
@@ -82,7 +58,7 @@
             </div>
           <% end %>
 
-          <% if current_obj.state_label.in? ["Queued", "Running"] and current_obj.can_cancel? and @object.editable? %>
+          <% if current_obj.can_be_canceled? and @object.editable? %>
             <%# column offset 11 %>
             <div class="col-md-1 pipeline-instance-spacing">
               <%= form_tag "#{current_obj.uri}/cancel", remote: true, style: "display:inline; padding-left: 1em" do |f| %>
diff --git a/apps/workbench/app/views/work_unit/_show_component.html.erb b/apps/workbench/app/views/work_unit/_show_component.html.erb
index dbf1c11..9789934 100644
--- a/apps/workbench/app/views/work_unit/_show_component.html.erb
+++ b/apps/workbench/app/views/work_unit/_show_component.html.erb
@@ -8,7 +8,7 @@
       <div class="pull-right">
         <div class="container-fluid">
           <div class="row-fulid pipeline-instance-spacing">
-            <% if wu.state_label == 'Running' and wu.child_summary_str %>
+            <% if wu.is_running? and wu.child_summary_str %>
               <div class="col-md-8">
                 <%= wu.child_summary_str %>
               </div>
@@ -16,7 +16,7 @@
             <div class="col-md-3">
               <%= render partial: 'work_unit/progress', locals: {wu: wu} %>
             </div>
-            <% if wu.state_label.in? ["Queued", "Running"] and wu.can_cancel? and @object.editable? %>
+            <% if wu.can_be_canceled? and @object.editable? %>
                 <div class="col-md-1">
                   <%= form_tag "#{wu.uri}/cancel", remote: true, style: "display:inline; padding-left: 1em" do |f| %>
                     <%= hidden_field_tag :return_to, url_for(@object) %>
@@ -31,33 +31,25 @@
     <% end %>
 
     <div class="col-md-10" >
-      <% if wu.state_label == 'Paused' %>
+      <% if wu.is_paused? %>
         <p>
-          This <%= wu.title %> is paused. Children that are
-          already running will continue to run, but no new work will be submitted.
+          This <%= wu.title %> is paused. Children that are already running
+          will continue to run, but no new processes will be submitted.
         </p>
       <% end %>
 
       <% runningtime = determine_wallclock_runtime(wu.children) %>
+      <% walltime = 0 %>
+      <% if wu.started_at %>
+        <% walltime = if wu.finished_at then (wu.finished_at - wu.started_at) else (Time.now - wu.started_at) end %>
+      <% end %>
 
       <p>
-        <% if wu.started_at %>
-          This <%= wu.title %> started at <%= render_localized_date(wu.started_at) %>.
-          It
-          <% if wu.state_label == 'Complete' %>
-            completed in
-          <% elsif wu.state_label == 'Failed' %>
-            failed after
-          <% else %>
-            has been active for
-          <% end %>
-
-          <% walltime = if wu.finished_at then
-                          wu.finished_at - wu.started_at
-                        else
-                          Time.now - wu.started_at
-                        end %>
-
+        <% active_for_str = wu.started_and_active_for_str %>
+        <% if active_for_str %>
+          <%= active_for_str[0] %>
+          <%= render_localized_date(wu.started_at) %>.
+          <%= active_for_str[1] %>
           <%= if walltime > runningtime
                 render_runtime(walltime, false)
               else
@@ -65,23 +57,17 @@
               end %><% if wu.finished_at %> at <%= render_localized_date(wu.finished_at) %><% end %>.
         <% else %>
           <% if wu.state_label %> This <%= wu.title %> is <%= if wu.state_label == 'Running' then 'active' else wu.state_label.downcase end %>. <% end %>
-            <% walltime = 0 %>
         <% end %>
 
-        <% if wu.state_label == 'Failed' %>
+        <% if wu.is_failed? %>
           Check the Log tab for more detail about why it failed.
         <% end %>
       </p>
 
-      <% if wu.state_label %>
+      <% ran_for_str = wu.ran_for_str %>
+      <% if ran_for_str %>
         <p>
-            It
-            <% if wu.state_label == 'Running' %>
-              has run
-            <% else %>
-              ran
-            <% end %>
-            for
+            <%= ran_for_str %>
             <%
                 cputime = wu.children.map { |c|
                 if c.started_at

-----------------------------------------------------------------------


hooks/post-receive
-- 




More information about the arvados-commits mailing list