X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/acced3c41adda16e8ea8ee9581edd8879c00fcfa..2eb7a28fa7900a005bf48dc40dd1af16d0bc455d:/services/api/app/models/pipeline_instance.rb diff --git a/services/api/app/models/pipeline_instance.rb b/services/api/app/models/pipeline_instance.rb index 77a0736b00..f84c4a310f 100644 --- a/services/api/app/models/pipeline_instance.rb +++ b/services/api/app/models/pipeline_instance.rb @@ -10,6 +10,7 @@ class PipelineInstance < ArvadosModel before_validation :bootstrap_components before_validation :update_state before_validation :verify_status + before_validation :update_timestamps_when_state_changes before_create :set_state_before_save before_save :set_state_before_save @@ -136,4 +137,17 @@ class PipelineInstance < ArvadosModel end end + def update_timestamps_when_state_changes + return if not (state_changed? or new_record?) + + case state + when RunningOnServer, RunningOnClient + self.started_at ||= db_current_time + when Failed, Complete + current_time = db_current_time + self.started_at ||= current_time + self.finished_at ||= current_time + end + end + end