summaryrefslogtreecommitdiff
path: root/lib/gitlab/optimistic_locking.rb
blob: 17010d73c5704483d2265ab81357357536ef3ec5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
module Gitlab
  class OptimisticLocking
    def self.retry_lock(subject, &block)
      loop do
        begin
          subject.transaction do
            return block.call(subject)
          end
        rescue ActiveRecord::StaleObjectError
          subject.reload
        end
      end
    end
  end
end