debian-mirror-gitlab/lib/gitlab/optimistic_locking.rb

23 lines
458 B
Ruby
Raw Normal View History

2017-08-17 22:00:37 +05:30
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
2018-03-17 18:26:18 +05:30
2017-08-17 22:00:37 +05:30
subject.reload
end
end
end
alias_method :retry_optimistic_lock, :retry_lock
end
end