8018: Create new container if there are retriable container requests.
authorPeter Amstutz <peter.amstutz@curoverse.com>
Tue, 27 Sep 2016 21:18:06 +0000 (17:18 -0400)
committerPeter Amstutz <peter.amstutz@curoverse.com>
Tue, 27 Sep 2016 21:18:06 +0000 (17:18 -0400)
services/api/app/models/container.rb
services/api/app/models/container_request.rb

index c1c3eae94b7769f35c90e874b0805e537847da71..037712db0ddc3aa1efac3035abbf711eccd33621 100644 (file)
@@ -282,6 +282,27 @@ class Container < ArvadosModel
     # that are associated with this container.
     if self.state_changed? and [Complete, Cancelled].include? self.state
       act_as_system_user do
+
+        if self.state == Cancelled
+          retryable_requests = ContainerRequest.where("priority > 0 and state = 'Committed' and container_count < container_count_max")
+        else
+          retryable_requests = []
+        end
+
+        if retryable_requests.any?
+          c = Container.create!(command: self.command,
+                                cwd: self.cwd,
+                                environment: self.environment,
+                                output_path: self.output_path,
+                                container_image: self.container_image,
+                                mounts: self.mounts,
+                                runtime_constraints: self.runtime_constraints)
+          retryable_requests.each do |cr|
+            cr.container_uuid = c.uuid
+            cr.save!
+          end
+        end
+
         # Notify container requests associated with this container
         ContainerRequest.where(container_uuid: uuid,
                                :state => ContainerRequest::Committed).each do |cr|
index f2d327ed5877a03109f13932292353cc533a31c9..27401fc0b162e16be9a499aec9bef2c0a1e1929f 100644 (file)
@@ -176,6 +176,9 @@ class ContainerRequest < ArvadosModel
     if state_changed? and state == Committed and container_uuid.nil?
       resolve
     end
+    if self.container_uuid != self.container_uuid_was
+      self.container_count += 1
+    end
   end
 
   def validate_runtime_constraints