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

22 lines
416 B
Ruby
Raw Normal View History

2018-12-13 13:39:08 +05:30
# frozen_string_literal: true
2017-08-17 22:00:37 +05:30
module Gitlab
module OptimisticLocking
module_function
def retry_lock(subject, retries = 100, &block)
2018-10-15 14:42:47 +05:30
ActiveRecord::Base.transaction do
yield(subject)
2017-08-17 22:00:37 +05:30
end
2018-10-15 14:42:47 +05:30
rescue ActiveRecord::StaleObjectError
retries -= 1
raise unless retries >= 0
subject.reload
retry
2017-08-17 22:00:37 +05:30
end
alias_method :retry_optimistic_lock, :retry_lock
end
end