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