8876: remove some job specific bits and make them generic
authorradhika <radhika@curoverse.com>
Fri, 27 May 2016 20:57:31 +0000 (16:57 -0400)
committerradhika <radhika@curoverse.com>
Fri, 27 May 2016 20:57:31 +0000 (16:57 -0400)
apps/workbench/app/models/job_work_unit.rb
apps/workbench/app/models/proxy_work_unit.rb
apps/workbench/app/models/work_unit.rb
apps/workbench/app/views/work_unit/_component_detail.html.erb
apps/workbench/app/views/work_unit/_progress.html.erb
apps/workbench/app/views/work_unit/_show_child.html.erb
apps/workbench/app/views/work_unit/_show_component.html.erb

index 7f1c73f694fefb57fc52f157e73b62e1ac61c1f9..8fc328585712f8c9a51fd3628f9c2446ae75afea 100644 (file)
@@ -3,12 +3,6 @@ class JobWorkUnit < ProxyWorkUnit
     uuid = get(:uuid)
     items = []
 
-    # Job tasks - for now do not include job tasks
-    # tasks = JobTask.filter([['job_uuid', '=', uuid]]).results
-    # tasks.each do |t|
-    #   items << t.work_unit("task #{items.size}")
-    # end
-
     # Jobs components
     components = get(:components)
     uuids = components.andand.collect {|_, v| v}
@@ -67,6 +61,10 @@ class JobWorkUnit < ProxyWorkUnit
     get(:output)
   end
 
+  def child_summary
+    get(:tasks_summary)
+  end
+
   def can_cancel?
     true
   end
@@ -76,10 +74,6 @@ class JobWorkUnit < ProxyWorkUnit
     "/jobs/#{uuid}"
   end
 
-  def child_summary
-    get(:tasks_summary)
-  end
-
   def title
     "job"
   end
index 52c84473dcaec191efb48f7f4312a364690a31f0..97983618064591626be7bc22f2d00260a700f99d 100644 (file)
@@ -24,29 +24,20 @@ class ProxyWorkUnit < WorkUnit
 
   def created_at
     t = get(:created_at)
-    if t.andand.class == String
-      Time.parse t
-    else
-      t
-    end
+    t = Time.parse(t) if (t.andand.class == String)
+    t
   end
 
   def started_at
     t = get(:started_at)
-    if t.andand.class == String
-      Time.parse t
-    else
-      t
-    end
+    t = Time.parse(t) if (t.andand.class == String)
+    t
   end
 
   def finished_at
     t = get(:finished_at)
-    if t.andand.class == String
-      Time.parse t
-    else
-      t
-    end
+    t = Time.parse(t) if (t.andand.class == String)
+    t
   end
 
   def state_label
@@ -119,6 +110,11 @@ class ProxyWorkUnit < WorkUnit
     self.unreadable_children
   end
 
+  def readable?
+    resource_class = ArvadosBase::resource_class_for_uuid(uuid)
+    resource_class.where(uuid: [uuid]).first rescue nil
+  end
+
   protected
 
   def get key
index aea0f1270ef81b3a61196e78138bf2eb4311d916..7439128ed7e00257e78c9bc4c79b33584024e8cd 100644 (file)
@@ -1,6 +1,5 @@
 class WorkUnit
-  # This is just an abstract class that documents the WorkUnit interface; a
-  # class can implement the interface without being a subclass of WorkUnit.
+  # This is an abstract class that documents the WorkUnit interface
 
   def label
     # returns the label that was assigned when creating the work unit
@@ -39,12 +38,12 @@ class WorkUnit
   end
 
   def success?
-    # returnis true if the work unit finished successfully,
+    # returns true if the work unit finished successfully,
     # false if it has a permanent failure,
     # and nil if the final state is not determined.
   end
 
-  def progress 
+  def progress
     # returns a number between 0 and 1
   end
 
@@ -92,16 +91,20 @@ class WorkUnit
     # returns uuid or pdh of output data, if any
   end
 
+  def child_summary
+    # summary status of any children of this work unit
+  end
+
   def can_cancel?
-    # returns if this work unit is cancelable
+    # returns true if this work unit can be canceled
   end
 
-  def uri
-    # returns the uri for this work unit
+  def readable?
+    # is the proxied object readable by current user?
   end
 
-  def child_summary
-    # summary status of any children of this work unit
+  def uri
+    # returns the uri for this work unit
   end
 
   def title
index eeb78f9511732412cb2a5f86553302b3d91fa396..d68273a460ed93c54bb2bfb7a16599938302e19c 100644 (file)
@@ -4,7 +4,7 @@
             <table>
               <% [:uuid, :modified_by_user_uuid, :created_at, :started_at, :finished_at, :output, :priority].each do |k| %>
                 <% val = current_obj.send(k) if current_obj.respond_to?(k) %>
-                <% unless val.nil? %>
+                <% if val %>
                 <tr>
                   <td style="padding-right: 1em">
                     <%= k.to_s %>:
@@ -40,7 +40,7 @@
                  %>
               <% [:script, :repository, :script_version, :supplied_script_version, :nondeterministic].each do |k| %>
                 <% val = current_obj.send(k) if current_obj.respond_to?(k) %>
-                <% unless val.nil? %>
+                <% if val %>
                 <tr>
                   <td style="padding-right: 1em">
                     <%= k.to_s %>:
index caee25107a92f1288c251f08cede41aa7ce4c740..ef7dcd942d0f6d4d52b7cdf249ad96cb67a5eb25 100644 (file)
@@ -1,7 +1,12 @@
 <% if wu.state_label == 'Running' %>
-  <div class="progress" style="margin-bottom: 0px">
-    <span class="progress-bar progress-bar-<%= wu.state_bootstrap_class %>" style="width: <%= wu.progress*100 %>%;"></span>
-  </div>
+  <% if @object.uuid == wu.uuid and wu.progress == 0.0 %>
+    <span class="label label-<%= wu.state_bootstrap_class %>"> Active </span>
+  <% else%>
+    <div class="progress" style="margin-bottom: 0px">
+      <span class="progress-bar progress-bar-<%= wu.state_bootstrap_class %>" style="width: <%= wu.progress*100 %>%;">
+      </span>
+    </div>
+  <% end %>
 <% else %>
-  <span class="label label-<%= wu.state_bootstrap_class %>"><%= wu.state_label%></span>
+  <span class="label label-<%= wu.state_bootstrap_class %>"><%= wu.state_label %></span>
 <% end %>
index a93895ba8285a1b9ec524cd924d7b7b5f9c51b38..0824871fb279cf3c1b350c3f9dec1d643fef090d 100644 (file)
                 <% if current_obj.log_collection %>
                   <% logCollection = Collection.find? current_obj.log_collection %>
                   <% if logCollection %>
-                    <%= link_to "Log", job_path(current_obj.uuid, anchor: "Log") %>
+                    <%= link_to "Log", "#{current_obj.uri}#Log" %>
                   <% else %>
                     Log unavailable
                   <% end %>
                 <% end %>
               <% elsif current_obj.state_label == "Running" %>
-                <% job = Job.find? current_obj.uuid %>
-                <% if job %>
-                  <%= link_to "Log", job_path(current_obj.uuid, anchor: "Log") %>
+                <% if current_obj.readable? %>
+                  <%= link_to "Log", "#{current_obj.uri}#Log" %>
                 <% else %>
                   Log unavailable
                 <% end %>
               <%# column offset 8 %>
               <div class="col-md-3">
                 <span class="task-summary-status">
-                  <%= current_obj.child_summary[:done] %>&nbsp;<%= "task".pluralize(current_obj.child_summary[:done]) %> done,
-                  <%= current_obj.child_summary[:failed] %>&nbsp;failed,
-                  <%= current_obj.child_summary[:running] %>&nbsp;running,
-                  <%= current_obj.child_summary[:todo] %>&nbsp;pending
+                  <% if current_obj.child_summary[:done] %>
+                    <%= current_obj.child_summary[:done] %>&nbsp;<%= "child".pluralize(current_obj.child_summary[:done]) %> done,
+                  <% end %>
+                  <% if current_obj.child_summary[:failed] %>
+                    <%= current_obj.child_summary[:failed] %>&nbsp;failed,
+                  <% end %>
+                  <% if current_obj.child_summary[:running] %>
+                    <%= current_obj.child_summary[:running] %>&nbsp;running,
+                  <% end %>
+                  <% if current_obj.child_summary[:todo] %>
+                    <%= current_obj.child_summary[:todo] %>&nbsp;pending
+                  <% end %>
                 </span>
               </div>
             <% end %>
             </div>
           <% end %>
 
-          <% if current_obj.state_label.in? ["Queued", "Running"] and @object.work_unit.can_cancel? and @object.editable? %>
+          <% if current_obj.state_label.in? ["Queued", "Running"] and current_obj.can_cancel? 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| %>
                 <%= hidden_field_tag :return_to, url_for(@object) %>
-                <%= button_tag "Cancel", {class: 'btn btn-xs btn-danger', id: "cancel-job-button"} %>
+                <%= button_tag "Cancel", {class: 'btn btn-xs btn-danger', id: "cancel-child-button"} %>
               <% end %>
             </div>
           <% end %>
index a42c3c02da3bcb9fca701947f9fe65ad6909fad5..23ac3d393d5025cce157566036488982fe0a1ad0 100644 (file)
@@ -12,7 +12,7 @@
                 <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) %>
-                    <%= button_tag "Cancel", {class: 'btn btn-xs btn-danger', id: "cancel-job-button"} %>
+                    <%= button_tag "Cancel", {class: 'btn btn-xs btn-danger', id: "cancel-obj-button"} %>
                   <% end %>
                 </div>
             <% end %>
@@ -29,7 +29,7 @@
       <% if wu.state_label == 'Paused' %>
         <p>
           This <%= wu.title %> is paused. Children that are
-          already running will continue to run, but no new work units will be submitted.
+          already running will continue to run, but no new work will be submitted.
         </p>
       <% end %>
 
@@ -60,7 +60,7 @@
               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%>
+            <% walltime = 0 %>
         <% end %>
 
         <% if wu.state_label == 'Failed' %>
              locals: {error_name: "Unreadable components", backtrace: nil, wu: wu}) %>
 <% else %>
   <% @descendent_count = 0 if !@descendent_count %>
-  <% wu.children.each_with_index do |c, i| %>
+  <% wu.children.each do |c| %>
     <% @descendent_count += 1 %>
     <%= render(partial: 'work_unit/show_child', locals: {current_obj: c, i: @descendent_count, expanded: false}) %>
   <% end %>