add pipeline_invocations html view
authorTom Clegg <tom@clinicalfuture.com>
Mon, 14 Jan 2013 20:24:23 +0000 (12:24 -0800)
committerTom Clegg <tom@clinicalfuture.com>
Mon, 14 Jan 2013 20:25:14 +0000 (12:25 -0800)
app/controllers/pipeline_invocations_controller.rb [new file with mode: 0644]
app/models/pipeline_invocation.rb
app/views/pipeline_invocations/index.html.erb [new file with mode: 0644]

diff --git a/app/controllers/pipeline_invocations_controller.rb b/app/controllers/pipeline_invocations_controller.rb
new file mode 100644 (file)
index 0000000..de8b9eb
--- /dev/null
@@ -0,0 +1,5 @@
+class PipelineInvocationsController < ApplicationController
+  def index
+    @objects = model_class.order("created_at desc")
+  end
+end
index 96deabbc7bcadf377b78281b3ec5ad468f867ea1..98b5494461a102d14859be8ee3e5e3b41932900f 100644 (file)
@@ -4,6 +4,36 @@ class PipelineInvocation < ActiveRecord::Base
   belongs_to :pipeline, :foreign_key => :pipeline_uuid, :primary_key => :uuid
 
   before_validation :bootstrap_components
+  before_validation :update_success
+
+  def progress_table
+    begin
+      # v0 pipeline format
+      nrow = -1
+      components['steps'].collect do |step|
+        nrow += 1
+        row = [nrow, step['name']]
+        if step['output_data_locator']
+          row << 1.0
+        else
+          row << 0.0
+        end
+        row << (step['warehousejob']['id'] rescue nil)
+        row << (step['warehousejob']['revision'] rescue nil)
+        row << step['output_data_locator']
+        row << (Time.parse(step['warehousejob']['finishtime']) rescue nil)
+        row
+      end
+    rescue
+      []
+    end
+  end
+
+  def progress_ratio
+    t = progress_table
+    return 0 if t.size < 1
+    t.collect { |r| r[2] }.inject(0.0) { |sum,a| sum += a } / t.size
+  end
 
   protected
   def bootstrap_components
@@ -11,4 +41,10 @@ class PipelineInvocation < ActiveRecord::Base
       self.components = pipeline.components
     end
   end
+
+  def update_success
+    if components and progress_ratio == 1.0
+      self.success = true
+    end
+  end
 end
diff --git a/app/views/pipeline_invocations/index.html.erb b/app/views/pipeline_invocations/index.html.erb
new file mode 100644 (file)
index 0000000..0a841b6
--- /dev/null
@@ -0,0 +1,64 @@
+<table style="width:100%">
+  <tr class="contain-align-left">
+    <th>
+      success
+    </th><th>
+      active
+    </th><th>
+      % complete
+    </th><th>
+      uuid
+    </th><th>
+      pipeline uuid
+    </th><th>
+      name
+    </th><th>
+      last updated
+    </th>
+  </tr>
+
+  <% @objects.each do |o| %>
+
+  <% status = o.success ? 'success' : (o.success == false ? 'failure' : 'pending') %>
+
+  <tr class="pipeline-invocation-status pipeline-invocation-status-<%= status %>" data-showhide-selector="tr#extra-info-<%= o.uuid %>" style="cursor:pointer">
+    <td>
+      <%= status %>
+    </td><td>
+      <%= o.active ? 'yes' : '-' %>
+    </td><td>
+      <%= (o.progress_ratio * 1000).floor / 10 %>
+    </td><td>
+      <%= o.uuid %>
+    </td><td>
+      <%= o.pipeline_uuid %>
+    </td><td>
+      <%= o.name %>
+    </td><td>
+      <%= distance_of_time_in_words(o.updated_at, Time.now, true) + ' ago' if o.updated_at %>
+    </td>
+  </tr>
+
+  <% if  %>
+  <tr id="extra-info-<%= o.uuid %>" data-showhide-default>
+    <td colspan="7">
+      <table>
+       <% o.progress_table.each do |r| %>
+       <tr>
+         <% r[2] = "#{(r[2]*100).floor}%" %>
+         <% r[4] = r[4][0..5] rescue '' %>
+         <% r.each do |c| %>
+         <td>
+           <%= (c.is_a? Time) ? distance_of_time_in_words(c, Time.now, true) + ' ago' : c %>
+         </td>
+         <% end %>
+       </tr>
+       <% end %>
+      </table>
+      </dl>
+    </td>
+  </tr>
+
+  <% end %>
+  <% end %>
+</table>