diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-08-18 11:17:02 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-08-18 11:17:02 +0300 |
commit | b39512ed755239198a9c294b6a45e65c05900235 (patch) | |
tree | d234a3efade1de67c46b9e5a38ce813627726aa7 /lib/gitlab/exclusive_lease_helpers | |
parent | d31474cf3b17ece37939d20082b07f6657cc79a9 (diff) |
Add latest changes from gitlab-org/gitlab@15-3-stable-eev15.3.0-rc42
Diffstat (limited to 'lib/gitlab/exclusive_lease_helpers')
-rw-r--r-- | lib/gitlab/exclusive_lease_helpers/sleeping_lock.rb | 6 |
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 |