end
def setup_instance
- @instance ||= PipelineInstance.
- create(:components => @components,
+ if $options[:submit]
+ @instance ||= PipelineInstance.
+ create(:components => @components,
:pipeline_template_uuid => @template[:uuid],
:active => true)
+ else
+ @instance ||= PipelineInstance.
+ create(:components => @components,
+ :pipeline_template_uuid => @template[:uuid],
+ :state => 'RunningOnClient',
+ :active => false)
+ end
self
end
def run
moretodo = true
+ interrupted = false
+
while moretodo
moretodo = false
@components.each do |cname, c|
sleep 10
rescue Interrupt
debuglog "interrupt", 0
- abort
+ interrupted = true
+ break
+ #abort
end
end
end
end
end
- if ended == @components.length or failed > 0
- @instance[:active] = false
- @instance[:success] = (succeeded == @components.length)
+ success = (succeeded == @components.length)
+
+ if interrupted
+ if success
+ @instance[:active] = false
+ @instance[:success] = success
+ @instance[:state] = "Complete"
+ else
+ @instance[:active] = nil
+ @instance[:success] = nil
+ @instance[:state] = 'Paused'
+ end
+ else
+ if ended == @components.length or failed > 0
+ @instance[:active] = false
+ @instance[:success] = success
+ @instance[:state] = success ? "Complete" : "Failed"
+ end
end
+ # set components_summary
+ components_summary = {"todo" => @components.length - ended, "done" => succeeded, "failed" => failed}
+ @instance[:components_summary] = components_summary
+
@instance.save
end
end
def verify_status
- if active_changed?
- if self.active
- self.state = RunningOnServer
- else
- if self.components_look_ready?
- 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, Paused
- self.active = false
+ self.active = nil
self.success = nil
when RunningOnServer
self.active = true
else
return false
end
- elsif components_changed?
+ elsif 'success'.in? changed_attributes
+ if self.success
+ self.active = false
+ self.state = Complete
+ else
+ self.active = false
+ self.state = Failed
+ end
+ elsif 'active'.in? changed_attributes
+ if self.active
+ self.state = RunningOnServer
+ else
+ if self.components_look_ready?
+ self.state = Ready
+ else
+ self.state = New
+ end
+ end
+ elsif 'components'.in? changed_attributes
if !self.state || self.state == New || !self.active
if self.components_look_ready?
self.state = Ready