gitlab-org--gitlab-foss/lib/gitlab/optimistic_locking.rb
Jacopo 181cd299f9 Adds Rubocop rule for line break after guard clause
Adds a rubocop rule (with autocorrect) to ensure line break after guard clauses.
2017-11-16 17:58:29 +01:00

22 lines
458 B
Ruby

module Gitlab
module OptimisticLocking
module_function
def retry_lock(subject, retries = 100, &block)
loop do
begin
ActiveRecord::Base.transaction do
return yield(subject)
end
rescue ActiveRecord::StaleObjectError
retries -= 1
raise unless retries >= 0
subject.reload
end
end
end
alias_method :retry_optimistic_lock, :retry_lock
end
end