2018-06-27 07:23:28 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2020-02-19 18:09:10 +00:00
|
|
|
class GitlabUsagePingWorker # rubocop:disable Scalability/IdempotentWorker
|
2020-08-05 03:10:58 +00:00
|
|
|
LEASE_KEY = 'gitlab_usage_ping_worker:ping'
|
2017-04-05 12:19:59 +00:00
|
|
|
LEASE_TIMEOUT = 86400
|
|
|
|
|
2017-11-28 16:08:30 +00:00
|
|
|
include ApplicationWorker
|
2020-08-05 03:10:58 +00:00
|
|
|
include CronjobQueue # rubocop:disable Scalability/CronWorkerContext
|
|
|
|
include Gitlab::ExclusiveLeaseHelpers
|
2017-04-05 12:19:59 +00:00
|
|
|
|
2020-02-18 18:09:07 +00:00
|
|
|
feature_category :collection
|
2020-08-05 03:10:58 +00:00
|
|
|
sidekiq_options retry: 3, dead: false
|
|
|
|
sidekiq_retry_in { |count| (count + 1) * 8.hours.to_i }
|
2019-07-17 12:50:37 +00:00
|
|
|
|
2017-04-05 12:19:59 +00:00
|
|
|
def perform
|
|
|
|
# Multiple Sidekiq workers could run this. We should only do this at most once a day.
|
2020-08-05 03:10:58 +00:00
|
|
|
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))
|
2017-05-24 10:25:44 +00:00
|
|
|
|
2020-08-05 03:10:58 +00:00
|
|
|
SubmitUsagePingService.new.execute
|
|
|
|
end
|
2017-04-05 12:19:59 +00:00
|
|
|
end
|
|
|
|
end
|