diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-08-20 21:42:06 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-08-20 21:42:06 +0300 |
commit | 6e4e1050d9dba2b7b2523fdd1768823ab85feef4 (patch) | |
tree | 78be5963ec075d80116a932011d695dd33910b4e /app/workers/gitlab_usage_ping_worker.rb | |
parent | 1ce776de4ae122aba3f349c02c17cebeaa8ecf07 (diff) |
Add latest changes from gitlab-org/gitlab@13-3-stable-ee
Diffstat (limited to 'app/workers/gitlab_usage_ping_worker.rb')
-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 |