3988: Update crunch-job, arv-run-pipeline-instance and workbench to read/write
authorPeter Amstutz <peter.amstutz@curoverse.com>
Wed, 24 Sep 2014 17:28:58 +0000 (13:28 -0400)
committerPeter Amstutz <peter.amstutz@curoverse.com>
Wed, 24 Sep 2014 17:28:58 +0000 (13:28 -0400)
"state" field of jobs instead of using running/success (+
cancelled_at/started_at/finished_at) to figure out what state the job is in.

apps/workbench/app/views/jobs/_show_recent.html.erb
apps/workbench/app/views/jobs/show.html.erb
apps/workbench/app/views/users/_tables.html.erb
sdk/cli/bin/arv-run-pipeline-instance
sdk/cli/bin/crunch-job

index b19b7d93ed13ac83c9ed6d66871846c727fb4aa8..c823fc590017d5d8ac304445f3d0c01d3065ec74 100644 (file)
@@ -83,7 +83,7 @@
             <td>
               <% if j.finished_at.is_a? Time %>
              <%= raw('ran&nbsp;' + distance_of_time_in_words(j.finished_at, j.started_at).sub('about ','~').sub(' ','&nbsp;')) %>
-              <% elsif j.running %>
+              <% elsif j.state == "Running" %>
               <span class="badge badge-success" title="tasks finished">&#x2714;&nbsp;<%= j.tasks_summary[:done] %></span>
               <span class="badge badge-info" title="tasks running">&#x2708;&nbsp;<%= j.tasks_summary[:running] %></span>
               <span class="badge" title="tasks todo">&#x2709;&nbsp;<%= j.tasks_summary[:todo] %></span>
index d3047ce119b5dbaac80cf40ddd193e2fd4851515..276aec5eb47228a8167d22f54f50eb66d4e4c215 100644 (file)
@@ -1,5 +1,5 @@
 <% content_for :tab_line_buttons do %>
-    <% if @object.running %>
+    <% if @object.state == "Running" %>
     <%= form_tag "/jobs/#{@object.uuid}/cancel", style: "display:inline; padding-left: 1em" do |f| %>
       <%= button_tag "Cancel running job", {class: 'btn btn-sm btn-danger', id: "cancel-job-button"} %>
     <% end %>
index ebb52019a9f57d3912c7cc4c9b2383eec689d9b6..acde5ce8fdd88ee376abfdb294ec1fb225390951 100644 (file)
@@ -59,7 +59,7 @@
 
             <td>
               <small>
-                <% if j.success and j.output %>
+                <% if j.state == "Complete" and j.output %>
                   <a href="<%= collection_path(j.output) %>">
                     <% collections = collections_for_object(j.output) %>
                       <% if collections && !collections.empty? %>
index 472c20bd73a283feb3149c44b6b3f534d3ed50bb..bc87c5deabc899e1d1bd02b787877755c2a32f44 100755 (executable)
@@ -509,7 +509,7 @@ class WhRunPipelineInstance
         # the job's current state")
         c_already_finished = (c[:job] &&
                               c[:job][:uuid] &&
-                              !c[:job][:success].nil?)
+                              ["Complete", "Failed", "Cancelled"].include? c[:job][:state])
         if !c[:job] and
             c[:script_parameters].select { |pname, p| p.is_a? Hash and p[:output_of]}.empty?
           # No job yet associated with this component and is component inputs
@@ -526,6 +526,7 @@ class WhRunPipelineInstance
             :owner_uuid => owner_uuid,
             :is_locked_by_uuid => (@options[:run_jobs_here] ? owner_uuid : nil),
             :submit_id => my_submit_id,
+            :state => (if @options[:run_jobs_here] then "Running" else "Queued")
           }, {
             # This is the right place to put these attributes when
             # dealing with new API servers.
@@ -546,7 +547,7 @@ class WhRunPipelineInstance
           end
         end
 
-        if c[:job] and c[:run_in_process] and c[:job][:success].nil?
+        if c[:job] and c[:run_in_process] and not ["Complete", "Failed", "Cancelled"].include? c[:job][:state]
           report_status
           begin
             require 'open3'
@@ -575,21 +576,18 @@ class WhRunPipelineInstance
             debuglog "Interrupted (#{e}). Failing job.", 0
             $arv.job.update(uuid: c[:job][:uuid],
                             job: {
-                              finished_at: Time.now,
-                              running: false,
-                              success: false
+                              state: "Failed"
                             })
           end
         end
 
         if c[:job] and c[:job][:uuid]
-          if (c[:job][:running] or
-              not (c[:job][:finished_at] or c[:job][:cancelled_at]))
+          if c[:job][:state] == "Running"
             # Job is running so update copy of job record
             c[:job] = JobCache.get(c[:job][:uuid])
           end
 
-          if c[:job][:success]
+          if c[:job][:state] == "Complete"
             # Populate script_parameters of other components waiting for
             # this job
             @components.each do |c2name, c2|
@@ -654,8 +652,7 @@ class WhRunPipelineInstance
                 end
               end
             end
-          elsif c[:job][:running] ||
-              (!c[:job][:started_at] && !c[:job][:cancelled_at])
+          elsif c[:job][:state] == "Running"
             # Job is still running
             moretodo = true
           elsif c[:job][:cancelled_at]
@@ -686,21 +683,17 @@ class WhRunPipelineInstance
       end
     end
 
-    ended = 0
-    succeeded = 0
-    failed = 0
-    @components.each do |cname, c|
-      if c[:job]
-        if c[:job][:finished_at] or c[:job][:cancelled_at] or (c[:job][:running] == false and c[:job][:success] == false)
-          ended += 1
-          if c[:job][:success] == true
-            succeeded += 1
-          elsif c[:job][:success] == false or c[:job][:cancelled_at]
-            failed += 1
-          end
-        end
-      end
-    end
+    ended = @components.map { |cname, c| 
+      if c[:job] and ["Complete", "Failed", "Cancelled"].include? c[:job][:state] then 1 else 0 end 
+    }.reduce(:+) || 0
+
+    succeeded = @components.map { |cname, c| 
+      if c[:job] and ["Complete"].include? c[:job][:state] then 1 else 0 end 
+    }.reduce(:+) || 0
+
+    failed = @components.map { |cname, c| 
+      if c[:job] and ["Failed", "Cancelled"].include? c[:job][:state] then 1 else 0  end 
+    }.reduce(:+) || 0
 
     success = (succeeded == @components.length)
 
@@ -766,19 +759,15 @@ class WhRunPipelineInstance
         @components.each do |cname, c|
           jstatus = if !c[:job]
                       "-"
-                    elsif c[:job][:running]
+                    elsif c[:job][:state] == "Running"
                       "#{c[:job][:tasks_summary].inspect}"
-                    elsif c[:job][:success]
+                    elsif c[:job][:state] == "Complete"
                       c[:job][:output]
-                    elsif c[:job][:cancelled_at]
+                    elsif c[:job][:state] == "Cancelled"
                       "cancelled #{c[:job][:cancelled_at]}"
-                    elsif c[:job][:finished_at]
+                    elsif c[:job][:state] == "Failed"
                       "failed #{c[:job][:finished_at]}"
-                    elsif c[:job][:started_at]
-                      "started #{c[:job][:started_at]}"
-                    elsif c[:job][:is_locked_by_uuid]
-                      "starting #{c[:job][:started_at]}"
-                    else
+                    elsif c[:job][:state] == "Queued"
                       "queued #{c[:job][:created_at]}"
                     end
           f.puts "#{cname.to_s.ljust namewidth} #{c[:job] ? c[:job][:uuid] : '-'.ljust(27)} #{jstatus}"
index 70f379e53fd9cc307bd933bc1b21276097863e4a..3dd1627a7d7a65380dd346387e142c481f46f5b4 100755 (executable)
@@ -161,6 +161,10 @@ if ($job_has_uuid)
       Log(undef, "Job is locked by " . $Job->{'is_locked_by_uuid'});
       exit EX_TEMPFAIL;
     }
+    if ($Job->{'state'} ne 'Queued') {
+      Log(undef, "Job state is " . $Job->{'state'} . ", but I can only start queued jobs.");
+      exit EX_TEMPFAIL;
+    }
     if ($Job->{'success'} ne undef) {
       Log(undef, "Job 'success' flag (" . $Job->{'success'} . ") is not null");
       exit EX_TEMPFAIL;
@@ -287,9 +291,7 @@ if ($job_has_uuid)
     Log(undef, "Error while updating / locking job, exiting ".EX_TEMPFAIL);
     exit EX_TEMPFAIL;
   }
-  $Job->update_attributes('started_at' => scalar gmtime,
-                          'running' => 1,
-                          'success' => undef,
+  $Job->update_attributes('state' => 'Running',
                           'tasks_summary' => { 'failed' => 0,
                                                'todo' => 1,
                                                'running' => 0,
@@ -876,12 +878,14 @@ Log (undef, "finish");
 save_meta();
 
 if ($job_has_uuid) {
-  $Job->update_attributes('running' => 0,
-                          'success' => $collated_output && $main::success,
-                          'finished_at' => scalar gmtime)
+  if ($collated_output && $main::success) {
+    $Job->update_attributes('state' => 'Complete')
+  } else {
+    $Job->update_attributes('state' => 'Failed')
+  }
 }
 
-exit ($Job->{'success'} ? 1 : 0);
+exit ($Job->{'state'} != 'Complete' ? 1 : 0);
 
 
 
@@ -1336,9 +1340,12 @@ sub croak
 sub cleanup
 {
   return if !$job_has_uuid;
-  $Job->update_attributes('running' => 0,
-                          'success' => 0,
-                          'finished_at' => scalar gmtime);
+  if ($Job->{'cancelled_at'}) {
+    $Job->update_attributes('state' => 'Cancelled',
+                            'finished_at' => scalar gmtime);
+  } else {
+    $Job->update_attributes('state' => 'Failed');
+  }
 }