diff options
author | Lin Jen-Shin <godfat@godfat.org> | 2019-09-03 06:31:58 +0000 |
---|---|---|
committer | Lin Jen-Shin <godfat@godfat.org> | 2019-09-03 06:31:58 +0000 |
commit | abd9e842720fc434c643cfe3f1662923c92f68f3 (patch) | |
tree | 2af7e16240c559b83f25e86968214f38590aea4f | |
parent | 991143eb1f1bb5cda1f709ad44fdc021aa12b75d (diff) | |
parent | 6889196116140577e2bce62be0a7784dbfa6e4ff (diff) | |
download | gitlab-ce-abd9e842720fc434c643cfe3f1662923c92f68f3.tar.gz |
Merge branch 'ce-12996-cancel-redundant-pipelines' into 'master'
Backport retries options for cancel_running
See merge request gitlab-org/gitlab-ce!32525
-rw-r--r-- | app/models/ci/pipeline.rb | 8 | ||||
-rw-r--r-- | lib/gitlab/optimistic_locking.rb | 3 |
2 files changed, 6 insertions, 5 deletions
diff --git a/app/models/ci/pipeline.rb b/app/models/ci/pipeline.rb index 64e372878e6..63070d4901f 100644 --- a/app/models/ci/pipeline.rb +++ b/app/models/ci/pipeline.rb @@ -460,8 +460,8 @@ module Ci canceled? && auto_canceled_by_id? end - def cancel_running - retry_optimistic_lock(cancelable_statuses) do |cancelable| + def cancel_running(retries: nil) + retry_optimistic_lock(cancelable_statuses, retries) do |cancelable| cancelable.find_each do |job| yield(job) if block_given? job.cancel @@ -469,10 +469,10 @@ module Ci end end - def auto_cancel_running(pipeline) + def auto_cancel_running(pipeline, retries: nil) update(auto_canceled_by: pipeline) - cancel_running do |job| + cancel_running(retries: retries) do |job| job.auto_canceled_by = pipeline end end diff --git a/lib/gitlab/optimistic_locking.rb b/lib/gitlab/optimistic_locking.rb index 0c0f46d3b77..d51d718c826 100644 --- a/lib/gitlab/optimistic_locking.rb +++ b/lib/gitlab/optimistic_locking.rb @@ -4,7 +4,8 @@ module Gitlab module OptimisticLocking module_function - def retry_lock(subject, retries = 100, &block) + def retry_lock(subject, retries = nil, &block) + retries ||= 100 # TODO(Observability): We should be recording details of the number of retries and the duration of the total execution here ActiveRecord::Base.transaction do yield(subject) |