diff options
author | Kamil Trzcinski <ayufan@ayufan.eu> | 2016-10-27 12:34:09 +0100 |
---|---|---|
committer | Kamil Trzcinski <ayufan@ayufan.eu> | 2016-10-27 12:34:35 +0100 |
commit | 2822526e7b996c90fb3bbd7c286c2777e5e37360 (patch) | |
tree | 6fb6a4951ad4b651193a62e69038fa673cf9b7bc /lib | |
parent | 39c17ccb875a90a019a1ac1e9f6c081693197ee8 (diff) | |
download | gitlab-ce-2822526e7b996c90fb3bbd7c286c2777e5e37360.tar.gz |
Make retry_lock to not be infiniteuse-optimistic-locking
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 |