Merge branch '8018-container-retry' closes #8018
authorPeter Amstutz <peter.amstutz@curoverse.com>
Fri, 7 Oct 2016 18:32:15 +0000 (14:32 -0400)
committerPeter Amstutz <peter.amstutz@curoverse.com>
Fri, 7 Oct 2016 18:32:15 +0000 (14:32 -0400)
1  2 
services/api/app/models/container.rb
services/api/app/models/container_request.rb
services/api/config/application.default.yml
services/api/test/unit/container_request_test.rb

index a60ea427b78649ae15977b69bea99060e9c465c9,29af22329c9717989d7d0e4541bdc0c9d40184bd..43c5b30a1f603fd94b828b3449f71c01b5ba716a
@@@ -307,9 -282,36 +307,36 @@@ class Container < ArvadosMode
      # 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_attrs = {
+             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
+           }
+           c = Container.create! c_attrs
+           retryable_requests.each do |cr|
+             cr.with_lock do
+               # Use row locking because this increments container_count
+               cr.container_uuid = c.uuid
+               cr.save
+             end
+           end
+         end
          # Notify container requests associated with this container
          ContainerRequest.where(container_uuid: uuid,
 -                               :state => ContainerRequest::Committed).each do |cr|
 +                               state: ContainerRequest::Committed).each do |cr|
            cr.container_completed!
          end