gitlab-org--gitlab-foss/lib/gitlab/optimistic_locking.rb

20 lines
385 B
Ruby
Raw Normal View History

2016-10-20 03:33:44 -04:00
module Gitlab
2016-10-27 07:34:09 -04:00
module OptimisticLocking
module_function
2016-10-27 07:34:09 -04:00
def retry_lock(subject, retries = 100, &block)
ActiveRecord::Base.transaction do
yield(subject)
2016-10-20 03:33:44 -04:00
end
rescue ActiveRecord::StaleObjectError
retries -= 1
raise unless retries >= 0
subject.reload
retry
2016-10-20 03:33:44 -04:00
end
alias_method :retry_optimistic_lock, :retry_lock
2016-10-20 03:33:44 -04:00
end
end