Merge branch 'ce-12996-cancel-redundant-pipelines' into 'master'
Backport retries options for cancel_running See merge request gitlab-org/gitlab-ce!32525
This commit is contained in:
commit
abd9e84272
2 changed files with 6 additions and 5 deletions
|
@ -460,8 +460,8 @@ module Ci
|
||||||
canceled? && auto_canceled_by_id?
|
canceled? && auto_canceled_by_id?
|
||||||
end
|
end
|
||||||
|
|
||||||
def cancel_running
|
def cancel_running(retries: nil)
|
||||||
retry_optimistic_lock(cancelable_statuses) do |cancelable|
|
retry_optimistic_lock(cancelable_statuses, retries) do |cancelable|
|
||||||
cancelable.find_each do |job|
|
cancelable.find_each do |job|
|
||||||
yield(job) if block_given?
|
yield(job) if block_given?
|
||||||
job.cancel
|
job.cancel
|
||||||
|
@ -469,10 +469,10 @@ module Ci
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def auto_cancel_running(pipeline)
|
def auto_cancel_running(pipeline, retries: nil)
|
||||||
update(auto_canceled_by: pipeline)
|
update(auto_canceled_by: pipeline)
|
||||||
|
|
||||||
cancel_running do |job|
|
cancel_running(retries: retries) do |job|
|
||||||
job.auto_canceled_by = pipeline
|
job.auto_canceled_by = pipeline
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -4,7 +4,8 @@ module Gitlab
|
||||||
module OptimisticLocking
|
module OptimisticLocking
|
||||||
module_function
|
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
|
# TODO(Observability): We should be recording details of the number of retries and the duration of the total execution here
|
||||||
ActiveRecord::Base.transaction do
|
ActiveRecord::Base.transaction do
|
||||||
yield(subject)
|
yield(subject)
|
||||||
|
|
Loading…
Reference in a new issue