diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/gitlab/optimistic_locking.rb | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/lib/gitlab/optimistic_locking.rb b/lib/gitlab/optimistic_locking.rb index 17010d73c57..879d46446b3 100644 --- a/lib/gitlab/optimistic_locking.rb +++ b/lib/gitlab/optimistic_locking.rb @@ -1,12 +1,16 @@ module Gitlab - class OptimisticLocking - def self.retry_lock(subject, &block) + module OptimisticLocking + extend self + + def retry_lock(subject, retries = 100, &block) loop do begin - subject.transaction do + ActiveRecord::Base.transaction do return block.call(subject) end rescue ActiveRecord::StaleObjectError + retries -= 1 + raise unless retries >= 0 subject.reload end end |