Merge branch '8484-sanity-check-collection-count' closes #8484
[arvados.git] / services / api / app / models / container.rb
index 33607af7be33a2534340b62884c6a606f8878ca8..787047df68e877bc8944b3c23186cc400c3ae227 100644 (file)
@@ -16,7 +16,7 @@ class Container < ArvadosModel
   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
 
@@ -25,6 +25,7 @@ class Container < ArvadosModel
     t.add :container_image
     t.add :cwd
     t.add :environment
+    t.add :exit_code
     t.add :finished_at
     t.add :log
     t.add :mounts
@@ -124,7 +125,7 @@ class Container < ArvadosModel
 
     when Complete
       if self.state_changed?
-        permitted.push :state, :finished_at, :output, :log
+        permitted.push :state, :finished_at, :output, :log, :exit_code
       else
         errors.add :state, "cannot update record"
       end
@@ -147,16 +148,15 @@ 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
       act_as_system_user do
-        # Try to close container requests associated with this container
+        # Notify container requests associated with this container
         ContainerRequest.where(container_uuid: uuid,
                                :state => ContainerRequest::Committed).each do |cr|
-          cr.state = ContainerRequest::Final
-          cr.save
+          cr.container_completed!
         end
 
         # Try to cancel any outstanding container requests made by this container.