X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/680bc629dc473d877218b1ed9351fac4020d4657..9997ada67ce36d2fbe831bce473aa61250727aff:/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 dada5d6836..55efa0ae85 100644 --- a/services/api/app/models/pipeline_instance.rb +++ b/services/api/app/models/pipeline_instance.rb @@ -1,3 +1,7 @@ +# Copyright (C) The Arvados Authors. All rights reserved. +# +# SPDX-License-Identifier: AGPL-3.0 + class PipelineInstance < ArvadosModel include HasUuid include KindAndEtag @@ -10,9 +14,9 @@ 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 - before_save :update_timestamps_when_state_changes api_accessible :user, extend: :common do |t| t.add :pipeline_template_uuid @@ -38,6 +42,10 @@ class PipelineInstance < ArvadosModel (Complete = 'Complete'), ] + def self.limit_index_columns_read + ["components"] + end + # if all components have input, the pipeline is Ready def components_look_ready? if !self.components || self.components.empty? @@ -100,6 +108,33 @@ class PipelineInstance < ArvadosModel self.where("state = 'RunningOnServer'") end + def cancel(cascade: false, need_transaction: true) + if need_transaction + ActiveRecord::Base.transaction do + cancel(cascade: cascade, need_transaction: false) + end + return + end + + if self.state.in?([RunningOnServer, RunningOnClient]) + self.state = Paused + self.save! + elsif self.state != Paused + raise InvalidStateTransitionError + end + + return if !cascade + + # cancel all child jobs + children = self.components.andand.collect{|_, c| c['job']}.compact.collect{|j| j['uuid']}.compact + + return if children.empty? + + Job.where(uuid: children, state: [Job::Queued, Job::Running]).each do |job| + job.cancel(cascade: cascade, need_transaction: false) + end + end + protected def bootstrap_components if pipeline_template and (!components or components.empty?) @@ -144,7 +179,9 @@ class PipelineInstance < ArvadosModel when RunningOnServer, RunningOnClient self.started_at ||= db_current_time when Failed, Complete - self.finished_at ||= db_current_time + current_time = db_current_time + self.started_at ||= current_time + self.finished_at ||= current_time end end