class PipelineInstance < ArvadosModel
- include AssignUuid
+ include HasUuid
include KindAndEtag
include CommonApiTemplate
serialize :components, Hash
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
end
def self.queue
- self.where("active = true or state = 'RunningOnClient'")
+ self.where("state = 'RunningOnServer'")
end
protected
self.active = true
self.success = nil
when RunningOnClient
- self.active = false
+ self.active = nil
self.success = nil
when Failed
self.active = false
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
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