From 415347a3354031b48c22cae56c7bbfdcb76d607c Mon Sep 17 00:00:00 2001 From: radhika Date: Fri, 2 May 2014 12:09:31 -0400 Subject: [PATCH] 2352: Update arv-run-pipeline-instance to handle RunningOnClient and Paused states --- sdk/cli/bin/arv-run-pipeline-instance | 43 ++++++++++++++++--- services/api/app/models/pipeline_instance.rb | 44 ++++++++++---------- 2 files changed, 60 insertions(+), 27 deletions(-) diff --git a/sdk/cli/bin/arv-run-pipeline-instance b/sdk/cli/bin/arv-run-pipeline-instance index 0b0553cb84..2751c08ef1 100755 --- a/sdk/cli/bin/arv-run-pipeline-instance +++ b/sdk/cli/bin/arv-run-pipeline-instance @@ -413,15 +413,25 @@ class WhRunPipelineInstance 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| @@ -544,7 +554,9 @@ class WhRunPipelineInstance sleep 10 rescue Interrupt debuglog "interrupt", 0 - abort + interrupted = true + break + #abort end end end @@ -565,11 +577,30 @@ class WhRunPipelineInstance 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 diff --git a/services/api/app/models/pipeline_instance.rb b/services/api/app/models/pipeline_instance.rb index ca4b69c62a..73f56d1344 100644 --- a/services/api/app/models/pipeline_instance.rb +++ b/services/api/app/models/pipeline_instance.rb @@ -139,28 +139,12 @@ class PipelineInstance < ArvadosModel 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 @@ -178,7 +162,25 @@ class PipelineInstance < ArvadosModel 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 -- 2.30.2