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

22 lines
415 B
Ruby
Raw Normal View History

# frozen_string_literal: true
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.reset
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