[ARVADOS] updated: 2e9cb970e94c1ba259c6365ea4b456ca87e85cee

Git user git at public.curoverse.com
Fri Feb 10 14:09:43 EST 2017


Summary of changes:
 .../api/app/controllers/arvados/v1/jobs_controller.rb   |  2 +-
 .../arvados/v1/pipeline_instances_controller.rb         |  2 +-
 services/api/app/models/job.rb                          | 17 ++++++++++++-----
 services/api/app/models/pipeline_instance.rb            | 13 ++++++++++---
 services/api/test/unit/job_test.rb                      |  4 ++--
 5 files changed, 26 insertions(+), 12 deletions(-)

       via  2e9cb970e94c1ba259c6365ea4b456ca87e85cee (commit)
      from  210af1cc7ede88914026fde078e45ef84c187a0c (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.


commit 2e9cb970e94c1ba259c6365ea4b456ca87e85cee
Author: radhika <radhika at curoverse.com>
Date:   Fri Feb 10 14:08:50 2017 -0500

    10903: support need_transaction for job and pipeline_instance cancel methods.

diff --git a/services/api/app/controllers/arvados/v1/jobs_controller.rb b/services/api/app/controllers/arvados/v1/jobs_controller.rb
index c38e419..bca74cd 100644
--- a/services/api/app/controllers/arvados/v1/jobs_controller.rb
+++ b/services/api/app/controllers/arvados/v1/jobs_controller.rb
@@ -46,7 +46,7 @@ class Arvados::V1::JobsController < ApplicationController
 
   def cancel
     reload_object_before_update
-    @object.cancel params[:cascade]
+    @object.cancel cascade: params[:cascade]
     show
   end
 
diff --git a/services/api/app/controllers/arvados/v1/pipeline_instances_controller.rb b/services/api/app/controllers/arvados/v1/pipeline_instances_controller.rb
index 476fc0a..c44c81a 100644
--- a/services/api/app/controllers/arvados/v1/pipeline_instances_controller.rb
+++ b/services/api/app/controllers/arvados/v1/pipeline_instances_controller.rb
@@ -5,7 +5,7 @@ class Arvados::V1::PipelineInstancesController < ApplicationController
 
   def cancel
     reload_object_before_update
-    @object.cancel params[:cascade]
+    @object.cancel cascade: params[:cascade]
     show
   end
 end
diff --git a/services/api/app/models/job.rb b/services/api/app/models/job.rb
index 5ce5ff2..d73d629 100644
--- a/services/api/app/models/job.rb
+++ b/services/api/app/models/job.rb
@@ -284,7 +284,14 @@ class Job < ArvadosModel
     end
   end
 
-  def cancel cascade=nil
+  def cancel(cascade: false, need_transaction: true)
+    if need_transaction
+      ActiveRecord::Base.transaction do
+        cancel(cascade: cascade, need_transaction: false)
+      end
+      return
+    end
+
     if self.state.in?([Queued, Running])
       self.state = Cancelled
       self.save!
@@ -300,13 +307,13 @@ class Job < ArvadosModel
     return if children.empty?
 
     # cancel any child jobs
-    Job.where(uuid: children).each do |job|
-      job.cancel cascade if job.state.in?([Queued, Running])
+    Job.where(uuid: children, state: [Queued, Running]).each do |job|
+      job.cancel(cascade: cascade, need_transaction: false)
     end
 
     # cancel any child pipelines
-    PipelineInstance.where(uuid: children).each do |pi|
-      pi.cancel cascade if pi.state.in?([PipelineInstance::RunningOnServer, PipelineInstance::RunningOnClient])
+    PipelineInstance.where(uuid: children, state: [PipelineInstance::RunningOnServer, PipelineInstance::RunningOnClient]).each do |pi|
+      pi.cancel(cascade: cascade, need_transaction: false)
     end
   end
 
diff --git a/services/api/app/models/pipeline_instance.rb b/services/api/app/models/pipeline_instance.rb
index 651f36d..75903ca 100644
--- a/services/api/app/models/pipeline_instance.rb
+++ b/services/api/app/models/pipeline_instance.rb
@@ -100,7 +100,14 @@ class PipelineInstance < ArvadosModel
     self.where("state = 'RunningOnServer'")
   end
 
-  def cancel cascade=nil
+  def cancel(cascade: false, need_transaction: true)
+    if need_transaction
+      ActiveRecord::Base.transaction do
+        cancel(cascade: cascade, need_transaction: false)
+      end
+      return
+    end
+
     if self.state.in?([RunningOnServer, RunningOnClient])
       self.state = Paused
       self.save!
@@ -115,8 +122,8 @@ class PipelineInstance < ArvadosModel
 
     return if children.empty?
 
-    Job.where(uuid: children).each do |job|
-      job.cancel cascade if job.state.in?([Job::Queued, Job::Running])
+    Job.where(uuid: children, state: [Job::Queued, Job::Running]).each do |job|
+      job.cancel(cascade: cascade, need_transaction: false)
     end
   end
 
diff --git a/services/api/test/unit/job_test.rb b/services/api/test/unit/job_test.rb
index 72b7689..8355ccf 100644
--- a/services/api/test/unit/job_test.rb
+++ b/services/api/test/unit/job_test.rb
@@ -509,7 +509,7 @@ class JobTest < ActiveSupport::TestCase
   ].each do |cascade|
     test "cancel job with cascade #{cascade}" do
       job = Job.find_by_uuid jobs(:running_job_with_components_at_level_1).uuid
-      job.cancel cascade
+      job.cancel cascade: cascade
       assert_equal Job::Cancelled, job.state
 
       descendents = ['zzzzz-8i9sb-jobcomponentsl2',
@@ -542,7 +542,7 @@ class JobTest < ActiveSupport::TestCase
   test 'cancelling a job with circular relationship with another does not result in an infinite loop' do
     job = Job.find_by_uuid jobs(:running_job_2_with_circular_component_relationship).uuid
 
-    job.cancel true
+    job.cancel cascade: true
 
     assert_equal Job::Cancelled, job.state
 

-----------------------------------------------------------------------


hooks/post-receive
-- 




More information about the arvados-commits mailing list