[ARVADOS] updated: 1.1.1-58-g77a6645

Git user git at public.curoverse.com
Thu Nov 30 17:25:23 EST 2017


Summary of changes:
 services/api/app/models/container.rb             | 21 +++++++++++------
 services/api/test/unit/container_request_test.rb | 29 ++++++++++++++++++++++++
 2 files changed, 43 insertions(+), 7 deletions(-)

       via  77a6645f2a8710a22a43909469077122834c93e6 (commit)
      from  8167db395a144238b1702c2bb5a40e4dd7db26ca (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 77a6645f2a8710a22a43909469077122834c93e6
Author: Peter Amstutz <pamstutz at veritasgenetics.com>
Date:   Thu Nov 30 17:24:57 2017 -0500

    12574: Use after_save hook to update priority.  Add test.
    
    Arvados-DCO-1.1-Signed-off-by: Peter Amstutz <pamstutz at veritasgenetics.com>

diff --git a/services/api/app/models/container.rb b/services/api/app/models/container.rb
index 617902c..15d9725 100644
--- a/services/api/app/models/container.rb
+++ b/services/api/app/models/container.rb
@@ -31,6 +31,7 @@ class Container < ArvadosModel
   after_validation :assign_auth
   before_save :sort_serialized_attrs
   after_save :handle_completed
+  after_save :update_priority
 
   has_many :container_requests, :foreign_key => :container_uuid, :class_name => 'ContainerRequest', :primary_key => :uuid
   belongs_to :auth, :class_name => 'ApiClientAuthorization', :foreign_key => :auth_uuid, :primary_key => :uuid
@@ -90,14 +91,20 @@ class Container < ArvadosModel
               state: ContainerRequest::Committed).
         maximum('priority')
       self.save!
+    end
+  end
 
-      # Update the priority of child container requests to match new priority
-      # of the parent container.
-      ContainerRequest.where(requesting_container_uuid: self.uuid,
-                             state: ContainerRequest::Committed).each do |cr|
-        cr.priority = self.priority
-        cr.save
-      end
+  def update_priority
+    if self.priority_changed?
+      act_as_system_user do
+         # Update the priority of child container requests to match new priority
+         # of the parent container.
+         ContainerRequest.where(requesting_container_uuid: self.uuid,
+                                state: ContainerRequest::Committed).each do |cr|
+           cr.priority = self.priority
+           cr.save
+         end
+       end
     end
   end
 
diff --git a/services/api/test/unit/container_request_test.rb b/services/api/test/unit/container_request_test.rb
index e751d61..cecf7b8 100644
--- a/services/api/test/unit/container_request_test.rb
+++ b/services/api/test/unit/container_request_test.rb
@@ -293,6 +293,35 @@ class ContainerRequestTest < ActiveSupport::TestCase
     assert_equal 0, c2.priority
   end
 
+
+  test "Container makes container request, then changes priority" do
+    set_user_from_auth :active
+    cr = create_minimal_req!(priority: 5, state: "Committed", container_count_max: 1)
+
+    c = Container.find_by_uuid cr.container_uuid
+    assert_equal 5, c.priority
+
+    cr2 = create_minimal_req!
+    cr2.update_attributes!(priority: 5, state: "Committed", requesting_container_uuid: c.uuid, command: ["echo", "foo2"], container_count_max: 1)
+    cr2.reload
+
+    c2 = Container.find_by_uuid cr2.container_uuid
+    assert_equal 5, c2.priority
+
+    act_as_system_user do
+      c.priority = 10
+      c.save!
+    end
+
+    cr.reload
+
+    cr2.reload
+    assert_equal 10, cr2.priority
+
+    c2.reload
+    assert_equal 10, c2.priority
+  end
+
   [
     ['running_container_auth', 'zzzzz-dz642-runningcontainr'],
     ['active_no_prefs', nil],

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


hooks/post-receive
-- 




More information about the arvados-commits mailing list