10181: Merge branch 'master' into 10181-incremental-log
[arvados.git] / services / api / app / models / container.rb
index e8a70499a929ed0192015044e6abd0fe6eb46bcd..079ac4c29980406982ee849046c4e23dccbe7e5f 100644 (file)
@@ -39,6 +39,7 @@ class Container < ArvadosModel
   before_save :update_secret_mounts_md5
   before_save :scrub_secret_mounts
   before_save :clear_runtime_status_when_queued
+  after_save :update_cr_logs
   after_save :handle_completed
   after_save :propagate_priority
   after_commit { UpdatePriority.run_update_thread }
@@ -451,7 +452,7 @@ class Container < ArvadosModel
     if current_api_client_authorization.andand.uuid.andand == self.auth_uuid
       # The contained process itself can update progress indicators,
       # but can't change priority etc.
-      permitted = permitted & [:state, :progress, :output]
+      permitted = permitted & (progress_attrs + final_attrs + [:state] - [:log])
     elsif self.locked_by_uuid && self.locked_by_uuid != current_api_client_authorization.andand.uuid
       # When locked, progress fields cannot be updated by the wrong
       # dispatcher, even though it has admin privileges.
@@ -495,6 +496,19 @@ class Container < ArvadosModel
     end
   end
 
+  def update_cr_logs
+    # If self.final?, this update is superfluous: the final log/output
+    # update will be done when handle_completed calls finalize! on
+    # each requesting CR.
+    return if self.final? || !self.log_changed?
+    leave_modified_by_user_alone do
+      ContainerRequest.where(container_uuid: self.uuid).each do |cr|
+        cr.update_collections(container: self, collections: ['log'])
+        cr.save!
+      end
+    end
+  end
+
   def assign_auth
     if self.auth_uuid_changed?
       return errors.add :auth_uuid, 'is readonly'