X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/eed7af8f901adb263c870a2277ec166467a28d77..675794872a5d064cf0a8177d662555c04b0dae51:/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 5993f99e97..7bb814c60d 100644 --- a/services/api/app/models/pipeline_instance.rb +++ b/services/api/app/models/pipeline_instance.rb @@ -1,5 +1,5 @@ class PipelineInstance < ArvadosModel - include AssignUuid + include HasUuid include KindAndEtag include CommonApiTemplate serialize :components, Hash @@ -27,13 +27,16 @@ class PipelineInstance < ArvadosModel end # Supported states for a pipeline instance - New = 'New' - Ready = 'Ready' - RunningOnServer = 'RunningOnServer' - RunningOnClient = 'RunningOnClient' - Paused = 'Paused' - Failed = 'Failed' - Complete = 'Complete' + States = + [ + (New = 'New'), + (Ready = 'Ready'), + (RunningOnServer = 'RunningOnServer'), + (RunningOnClient = 'RunningOnClient'), + (Paused = 'Paused'), + (Failed = 'Failed'), + (Complete = 'Complete'), + ] def dependencies dependency_search(self.components).keys @@ -163,6 +166,7 @@ class PipelineInstance < ArvadosModel return false end elsif 'success'.in? changed_attributes + logger.info "pipeline_instance changed_attributes has success for #{self.uuid}" if self.success self.active = false self.state = Complete @@ -171,24 +175,39 @@ class PipelineInstance < ArvadosModel self.state = Failed end elsif 'active'.in? changed_attributes + logger.info "pipeline_instance changed_attributes has active for #{self.uuid}" if self.active - if self.state == New || self.state == Ready || self.state == Paused + if self.state.in? [New, Ready, Paused] self.state = RunningOnServer end else - if self.components_look_ready? + if self.state == RunningOnServer # state was RunningOnServer + self.active = nil + self.state = Paused + elsif self.components_look_ready? self.state = Ready else self.state = New end end + elsif new_record? and self.state.nil? + # No state, active, or success given + self.state = New end - if 'components'.in? changed_attributes - if self.components_look_ready? && (!self.state || self.state == New) + if new_record? or 'components'.in? changed_attributes + self.state ||= New + if self.state == New and self.components_look_ready? self.state = Ready end end + + if self.state.in?(States) + true + else + errors.add :state, "'#{state.inspect} must be one of: [#{States.join ', '}]" + false + end end def set_state_before_save