X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/d4939c581f629a19220bc5b469fed98462b2b7eb..8aeac20eed5c6eb2cc9f41ada60632265cbdd556:/services/api/app/models/container.rb?ds=sidebyside diff --git a/services/api/app/models/container.rb b/services/api/app/models/container.rb index 79c9868189..d777c0c2fe 100644 --- a/services/api/app/models/container.rb +++ b/services/api/app/models/container.rb @@ -13,10 +13,10 @@ class Container < ArvadosModel before_validation :fill_field_defaults, :if => :new_record? before_validation :set_timestamps - validates :command, :container_image, :output_path, :cwd, :presence => true + validates :command, :container_image, :output_path, :cwd, :priority, :presence => true validate :validate_state_change validate :validate_change - after_save :request_finalize + after_save :handle_completed has_many :container_requests, :foreign_key => :container_uuid, :class_name => 'ContainerRequest', :primary_key => :uuid @@ -57,16 +57,18 @@ class Container < ArvadosModel end def update_priority! - # Update the priority of this container to the maximum priority of any of - # its committed container requests and save the record. - max = 0 - ContainerRequest.where(container_uuid: uuid).each do |cr| - if cr.state == ContainerRequest::Committed and cr.priority > max - max = cr.priority + if [Queued, Running].include? self.state + # Update the priority of this container to the maximum priority of any of + # its committed container requests and save the record. + max = 0 + ContainerRequest.where(container_uuid: uuid).each do |cr| + if cr.state == ContainerRequest::Committed and cr.priority > max + max = cr.priority + end end + self.priority = max + self.save! end - self.priority = max - self.save! end protected @@ -145,7 +147,7 @@ class Container < ArvadosModel check_update_whitelist permitted end - def request_finalize + def handle_completed # This container is finished so finalize any associated container requests # that are associated with this container. if self.state_changed? and [Complete, Cancelled].include? self.state @@ -157,10 +159,10 @@ class Container < ArvadosModel cr.save end - # Try to close any outstanding container requests made by this container. + # Try to cancel any outstanding container requests made by this container. ContainerRequest.where(requesting_container_uuid: uuid, :state => ContainerRequest::Committed).each do |cr| - cr.state = ContainerRequest::Final + cr.priority = 0 cr.save end end