diff options
author | Douwe Maan <douwe@gitlab.com> | 2019-08-01 17:58:14 +0300 |
---|---|---|
committer | Douwe Maan <douwe@gitlab.com> | 2019-08-01 17:58:14 +0300 |
commit | c017dc578dc78729050792d22b449ce0529479cf (patch) | |
tree | 4ed307f81cf1f6468413e31b22e04f6388f7301f /lib/gitlab | |
parent | 354cd090521984dc95ce2ee2713b81a82aec2577 (diff) | |
parent | f4cd926cf3eec069396ab995b3553f40617c19e6 (diff) |
Merge branch 'osw-avoid-errors-due-to-concurrent-calls' into 'master'
Add exclusive lease to mergeability check process
See merge request gitlab-org/gitlab-ce!31082
Diffstat (limited to 'lib/gitlab')
-rw-r--r-- | lib/gitlab/exclusive_lease_helpers.rb | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/lib/gitlab/exclusive_lease_helpers.rb b/lib/gitlab/exclusive_lease_helpers.rb index 7961d4bbd6e..61eb030563d 100644 --- a/lib/gitlab/exclusive_lease_helpers.rb +++ b/lib/gitlab/exclusive_lease_helpers.rb @@ -15,17 +15,18 @@ module Gitlab raise ArgumentError, 'Key needs to be specified' unless key lease = Gitlab::ExclusiveLease.new(key, timeout: ttl) + retried = false until uuid = lease.try_obtain # Keep trying until we obtain the lease. To prevent hammering Redis too # much we'll wait for a bit. sleep(sleep_sec) - break if (retries -= 1) < 0 + (retries -= 1) < 0 ? break : retried ||= true end raise FailedToObtainLockError, 'Failed to obtain a lock' unless uuid - yield + yield(retried) ensure Gitlab::ExclusiveLease.cancel(key, uuid) end |