[ARVADOS] updated: f6cd6a5f0ca78c51c30e2689ca3d5a4caeb41073

git at public.curoverse.com git at public.curoverse.com
Fri Sep 19 12:24:23 EDT 2014


Summary of changes:
 services/api/app/models/job.rb     | 35 ++++++++++++++++++++++-------------
 services/api/test/unit/job_test.rb |  9 +++++++--
 2 files changed, 29 insertions(+), 15 deletions(-)

       via  f6cd6a5f0ca78c51c30e2689ca3d5a4caeb41073 (commit)
      from  51444751090ef020a33a125c636f9afc099f6a46 (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 f6cd6a5f0ca78c51c30e2689ca3d5a4caeb41073
Author: radhika <radhika at curoverse.com>
Date:   Fri Sep 19 12:22:46 2014 -0400

    3898: cancelled_at takes precedence over success flag.

diff --git a/services/api/app/models/job.rb b/services/api/app/models/job.rb
index cbfe46d..12f82be 100644
--- a/services/api/app/models/job.rb
+++ b/services/api/app/models/job.rb
@@ -266,7 +266,7 @@ class Job < ArvadosModel
           self.cancelled_at = Time.now
         end
         self.running = false
-        self.success = nil
+        self.success = false
       when Failed
         if !self.finished_at
           self.finished_at = Time.now
@@ -280,25 +280,35 @@ class Job < ArvadosModel
         self.running = false
         self.success = true
       end
-    elsif 'success'.in? changed_attributes
-      if self.success
-        self.state = Complete
-      else
-        self.state = Failed
-      end
-      if !self.finished_at
-        self.finished_at = Time.now
-      end
-      self.running = false
     elsif 'cancelled_at'.in? changed_attributes
       self.state = Cancelled
       self.running = false
+      self.success = false
+    elsif 'success'.in? changed_attributes
+      if self.cancelled_at
+        self.state = Cancelled
+        self.running = false
+        self.success = false
+      else
+        if self.success
+          self.state = Complete
+        else
+          self.state = Failed
+        end
+        if !self.finished_at
+          self.finished_at = Time.now
+        end
+        self.running = false
+      end
     elsif 'running'.in? changed_attributes
       if self.running
         self.state = Running
         if !self.started_at
           self.started_at = Time.now
         end
+      else
+        self.state = nil # let set_state_before_save determine what the state should be
+        self.started_at = nil
       end
     end
     true
@@ -314,8 +324,7 @@ class Job < ArvadosModel
         self.state = Failed
       elsif (self.running && self.success.nil? && !self.cancelled_at)
         self.state = Running
-      elsif !self.started_at && !self.cancelled_at && !self.is_locked_by_uuid &&
-            self.success.nil? && self.running.nil?
+      elsif !self.started_at && !self.cancelled_at && !self.is_locked_by_uuid && self.success.nil?
         self.state = Queued
       end
     end
diff --git a/services/api/test/unit/job_test.rb b/services/api/test/unit/job_test.rb
index 53aec28..29ce969 100644
--- a/services/api/test/unit/job_test.rb
+++ b/services/api/test/unit/job_test.rb
@@ -158,7 +158,7 @@ class JobTest < ActiveSupport::TestCase
   [
     # Each test case is of the following format
     # Array of parameters where each parameter is of the format:
-    #     attr name to be changed, attr value, (array of array of expectations OR the string "error")
+    #     attr name to be changed, attr value, and array of expectations (where each expectation is an array) OR the string "error"
     [['running', false, [['state', 'Queued']]]],
     [['state', 'Running', 'error']],  # is_locked_by_uuid is not set
     [['is_locked_by_uuid', 'use_current_user_uuid', [['state', 'Queued']]], ['state', 'Running', [['running', true], ['started_at', 'not_nil'], ['success', 'nil']]]],
@@ -166,9 +166,12 @@ class JobTest < ActiveSupport::TestCase
     [['running', true, [['state', 'Running']]], ['cancelled_at', Time.now, [['state', 'Cancelled'],['running', false],['started_at', 'not_nil']]]],
     [['running', true, [['state', 'Running']]], ['state', 'Cancelled', [['running', false],['cancelled_at', 'not_nil'],['started_at', 'not_nil']]]],
     [['running', true, [['state', 'Running']]], ['success', true, [['state', 'Complete'],['running', false],['finished_at', 'not_nil']]]],
-    [['running', true, [['state', 'Running']]], ['success', 'false', [['state', 'Failed'],['running', false],['finished_at', 'not_nil']]]],
+    [['running', true, [['state', 'Running']]], ['success', false, [['state', 'Failed'],['running', false],['finished_at', 'not_nil']]]],
     [['running', true, [['state', 'Running']]], ['state', 'Complete', [['success', true],['running', false],['finished_at', 'not_nil']]]],
     [['running', true, [['state', 'Running']]], ['state', 'Failed', [['success', false],['running', false],['finished_at', 'not_nil']]]],
+    [['running', true, [['state', 'Running'], ['started_at', 'not_nil']]], ['running', false, [['state', 'Queued']]]],
+    [['cancelled_at', Time.now, [['state', 'Cancelled'],['running', false]]], ['success', false, [['state', 'Cancelled'],['running', false],['finished_at', 'nil'], ['cancelled_at', 'not_nil']]]],
+    [['cancelled_at', Time.now, [['state', 'Cancelled'],['running', false]]], ['success', true, [['state', 'Cancelled'],['running', false],['finished_at', 'nil'],['cancelled_at', 'not_nil']]]],
     # potential migration cases
     [['state', nil, [['state', 'Queued']]]],
     [['state', nil, [['state', 'Queued']]], ['cancelled_at', Time.now, [['state', 'Cancelled']]]],
@@ -209,6 +212,8 @@ class JobTest < ActiveSupport::TestCase
               rescued = true
             end
             assert rescued, 'Expected error'
+          else
+            raise 'I do not know how to handle this expectation'
           end
         end
       end

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


hooks/post-receive
-- 




More information about the arvados-commits mailing list