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