2352: Update arv-run-pipeline-instance to handle RunningOnClient and Paused states
authorradhika <radhika@curoverse.com>
Fri, 2 May 2014 16:09:31 +0000 (12:09 -0400)
committerradhika <radhika@curoverse.com>
Fri, 2 May 2014 16:09:31 +0000 (12:09 -0400)
sdk/cli/bin/arv-run-pipeline-instance
services/api/app/models/pipeline_instance.rb

index 0b0553cb843e559a8f12af37fa1c2a9181acb6cc..2751c08ef1705aba2f8dfac9b34a26c90f50642f 100755 (executable)
@@ -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
 
index ca4b69c62a3c58f71a79ff6858c112fcc23e70ab..73f56d1344f7f2d7981c2f37bb3c739aa66b6ae9 100644 (file)
@@ -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