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
|
|
|
|
|
2019-07-31 22:56:46 +05:30
|
|
|
subject.reset
|
2018-10-15 14:42:47 +05:30
|
|
|
retry
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
alias_method :retry_optimistic_lock, :retry_lock
|
|
|
|
end
|
|
|
|
end
|