Welcome to mirror list, hosted at ThFree Co, Russian Federation.

optimistic_locking.rb « gitlab « lib - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: d09bce642b0953f06413da755e18e3efe110d647 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
module Gitlab
  module OptimisticLocking
    module_function

    def retry_lock(subject, retries = 100, &block)
      ActiveRecord::Base.transaction do
        yield(subject)
      end
    rescue ActiveRecord::StaleObjectError
      retries -= 1
      raise unless retries >= 0

      subject.reload
      retry
    end

    alias_method :retry_optimistic_lock, :retry_lock
  end
end