Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'lib/gitlab/exclusive_lease_helpers/sleeping_lock.rb')
-rw-r--r--lib/gitlab/exclusive_lease_helpers/sleeping_lock.rb6
1 files changed, 4 insertions, 2 deletions
diff --git a/lib/gitlab/exclusive_lease_helpers/sleeping_lock.rb b/lib/gitlab/exclusive_lease_helpers/sleeping_lock.rb
index 52035220a71..7ef3e738481 100644
--- a/lib/gitlab/exclusive_lease_helpers/sleeping_lock.rb
+++ b/lib/gitlab/exclusive_lease_helpers/sleeping_lock.rb
@@ -5,6 +5,8 @@ module Gitlab
# Wrapper around ExclusiveLease that adds retry logic
class SleepingLock
delegate :cancel, to: :@lease
+ MAX_ATTEMPTS = 65
+ DEFAULT_ATTEMPTS = 10
def initialize(key, timeout:, delay:)
@lease = ::Gitlab::ExclusiveLease.new(key, timeout: timeout)
@@ -12,9 +14,9 @@ module Gitlab
@attempts = 0
end
- def obtain(max_attempts)
+ def obtain(max_attempts = DEFAULT_ATTEMPTS)
until held?
- raise FailedToObtainLockError, 'Failed to obtain a lock' if attempts >= max_attempts
+ raise FailedToObtainLockError, 'Failed to obtain a lock' if attempts >= [max_attempts, MAX_ATTEMPTS].min
sleep(sleep_sec) unless first_attempt?
try_obtain