Module: Gitlab::OptimisticLocking

Included in:
Ci::Pipeline, Ci::Ref, Ci::RetryPipelineService, Ci::Stage, Terraform::RemoteStateHandler
Defined in:
lib/gitlab/optimistic_locking.rb

Class Method Summary collapse

Class Method Details

.retry_lock(subject, retries = nil, &block) ⇒ Object Also known as: retry_optimistic_lock


7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/gitlab/optimistic_locking.rb', line 7

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)
  end
rescue ActiveRecord::StaleObjectError
  retries -= 1
  raise unless retries >= 0

  subject.reset
  retry
end