diff options
author | Shinya Maeda <shinya@gitlab.com> | 2018-07-03 14:52:01 +0900 |
---|---|---|
committer | Shinya Maeda <shinya@gitlab.com> | 2018-07-03 14:52:01 +0900 |
commit | 53234295e587a5b55dcb9417a869642ba0c266aa (patch) | |
tree | d4b0cfb504bb2742b1d9a6811ea77c0beb584abb | |
parent | 902e69dedd1b4c60ce109c346b65c5e61a46ff4a (diff) | |
download | gitlab-ce-53234295e587a5b55dcb9417a869642ba0c266aa.tar.gz |
Rename retries and remove retry_max
-rw-r--r-- | app/services/concerns/exclusive_lease_lock.rb | 5 |
1 files changed, 2 insertions, 3 deletions
diff --git a/app/services/concerns/exclusive_lease_lock.rb b/app/services/concerns/exclusive_lease_lock.rb index 231cfd3e3c5..8da54b0d15d 100644 --- a/app/services/concerns/exclusive_lease_lock.rb +++ b/app/services/concerns/exclusive_lease_lock.rb @@ -3,15 +3,14 @@ module ExclusiveLeaseLock FailedToObtainLockError = Class.new(StandardError) - def in_lock(key, ttl: 1.minute, retry_max: 10, sleep_sec: 0.01.seconds) + def in_lock(key, ttl: 1.minute, retries: 10, sleep_sec: 0.01.seconds) lease = Gitlab::ExclusiveLease.new(key, timeout: ttl) - retry_count = 0 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 retry_max < (retry_count += 1) + break if (retries -= 1) < 0 end raise FailedToObtainLockError, 'Failed to obtain a lock' unless uuid |