X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/5cb205c567c312345376bcd2b7104075b5710d7f..eee2c981d6a29eb7f15b8957570bbf8515d3d947:/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 211b91a0e3..258ee2729a 100644 --- a/services/api/app/models/pipeline_instance.rb +++ b/services/api/app/models/pipeline_instance.rb @@ -40,17 +40,16 @@ class PipelineInstance < ArvadosModel end # if all components have input, the pipeline is Ready - def self.is_ready components - if !components || components.empty? # is this correct? - return true + def components_look_ready? + if !self.components || self.components.empty? + return false end all_components_have_input = true - components.each do |name, component| - component['script_parameters'].each do |parametername, parameter| + self.components.each do |name, component| + component['script_parameters'].andand.each do |parametername, parameter| parameter = { 'value' => parameter } unless parameter.is_a? Hash - if parameter['value'].nil? and - ![false,'false',0,'0'].index parameter['required'] + if parameter['value'].nil? and parameter['required'] if parameter['output_of'] next end @@ -99,7 +98,7 @@ class PipelineInstance < ArvadosModel end def self.queue - self.where('active = true') + self.where("active = true or state = 'RunningOnClient'") end protected @@ -140,28 +139,12 @@ class PipelineInstance < ArvadosModel end def verify_status - if active_changed? - if self.active - self.state = RunningOnServer - else - if PipelineInstance.is_ready self.components - self.state = Ready - else - self.state = New - end - end - elsif success_changed? - if self.success - self.active = false - self.state = Complete - else - self.active = false - self.state = Failed - end - elsif state_changed? + changed_attributes = self.changed + + if 'state'.in? changed_attributes case self.state - when New, Ready - self.active = false + when New, Ready, Paused + self.active = nil self.success = nil when RunningOnServer self.active = true @@ -172,29 +155,48 @@ class PipelineInstance < ArvadosModel when Failed self.active = false self.success = false + self.state = Failed # before_validation will fail if false is returned in the previous line when Complete self.active = false self.success = true + else + return false + end + elsif 'success'.in? changed_attributes + if self.success + self.active = false + self.state = Complete + else + self.active = false + self.state = Failed end - elsif components_changed? - if !self.state || self.state == New || !self.active - if PipelineInstance.is_ready self.components + elsif 'active'.in? changed_attributes + if self.active + if self.state == New || self.state == Ready || self.state == Paused + self.state = RunningOnServer + end + else + if self.components_look_ready? self.state = Ready else self.state = New end end end + + if 'components'.in? changed_attributes + if self.components_look_ready? && (!self.state || self.state == New) + self.state = Ready + end + end end def set_state_before_save - if !self.state || self.state == New + if !self.state || self.state == New || self.state == Ready || self.state == Paused if self.active self.state = RunningOnServer - elsif PipelineInstance.is_ready self.components + elsif self.components_look_ready? && (!self.state || self.state == New) self.state = Ready - else - self.state = New end end end