diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-08-05 06:10:58 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-08-05 06:10:58 +0300 |
commit | af7f4b8c377191ca243a673034ee85264353cf95 (patch) | |
tree | 6f0898197899eab78f8e9a92d604326136ecffe3 /app/workers | |
parent | 14497073dcf5ee76f9bbc169b4713c511b003faa (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app/workers')
-rw-r--r-- | app/workers/gitlab_usage_ping_worker.rb | 28 |
1 files changed, 10 insertions, 18 deletions
diff --git a/app/workers/gitlab_usage_ping_worker.rb b/app/workers/gitlab_usage_ping_worker.rb index 9f0cf1728dd..a696c6e746a 100644 --- a/app/workers/gitlab_usage_ping_worker.rb +++ b/app/workers/gitlab_usage_ping_worker.rb @@ -1,32 +1,24 @@ # frozen_string_literal: true class GitlabUsagePingWorker # rubocop:disable Scalability/IdempotentWorker + LEASE_KEY = 'gitlab_usage_ping_worker:ping' LEASE_TIMEOUT = 86400 include ApplicationWorker - # rubocop:disable Scalability/CronWorkerContext - # This worker does not perform work scoped to a context - include CronjobQueue - # rubocop:enable Scalability/CronWorkerContext + include CronjobQueue # rubocop:disable Scalability/CronWorkerContext + include Gitlab::ExclusiveLeaseHelpers feature_category :collection - - # Retry for up to approximately three hours then give up. - sidekiq_options retry: 10, dead: false + sidekiq_options retry: 3, dead: false + sidekiq_retry_in { |count| (count + 1) * 8.hours.to_i } def perform # Multiple Sidekiq workers could run this. We should only do this at most once a day. - return unless try_obtain_lease - - # Splay the request over a minute to avoid thundering herd problems. - sleep(rand(0.0..60.0).round(3)) - - SubmitUsagePingService.new.execute - end - - private + in_lock(LEASE_KEY, ttl: LEASE_TIMEOUT) do + # Splay the request over a minute to avoid thundering herd problems. + sleep(rand(0.0..60.0).round(3)) - def try_obtain_lease - Gitlab::ExclusiveLease.new('gitlab_usage_ping_worker:ping', timeout: LEASE_TIMEOUT).try_obtain + SubmitUsagePingService.new.execute + end end end |