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: 1d9a5d1a20a7c91d7fd5283bb6f4d7001f3cbb17 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
module Gitlab
  module OptimisticLocking
    module_function

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

          subject.reload
        end
      end
    end

    alias_method :retry_optimistic_lock, :retry_lock
  end
end