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
|
2017-04-05 08:19:59 -04:00
|
|
|
LEASE_TIMEOUT = 86400
|
|
|
|
|
2017-11-28 11:08:30 -05:00
|
|
|
include ApplicationWorker
|
2020-02-10 07:08:59 -05:00
|
|
|
# rubocop:disable Scalability/CronWorkerContext
|
|
|
|
# This worker does not perform work scoped to a context
|
|
|
|
include CronjobQueue
|
|
|
|
# rubocop:enable Scalability/CronWorkerContext
|
2017-04-05 08:19:59 -04:00
|
|
|
|
2020-02-18 13:09:07 -05:00
|
|
|
feature_category :collection
|
2019-10-18 07:11:44 -04:00
|
|
|
|
2019-07-17 08:50:37 -04:00
|
|
|
# Retry for up to approximately three hours then give up.
|
|
|
|
sidekiq_options retry: 10, dead: false
|
|
|
|
|
2017-04-05 08:19:59 -04:00
|
|
|
def perform
|
|
|
|
# Multiple Sidekiq workers could run this. We should only do this at most once a day.
|
|
|
|
return unless try_obtain_lease
|
|
|
|
|
2019-07-17 08:50:37 -04:00
|
|
|
# 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
|
|
|
SubmitUsagePingService.new.execute
|
2017-04-05 08:19:59 -04:00
|
|
|
end
|
|
|
|
|
2017-05-24 06:25:44 -04:00
|
|
|
private
|
|
|
|
|
2017-04-05 08:19:59 -04:00
|
|
|
def try_obtain_lease
|
|
|
|
Gitlab::ExclusiveLease.new('gitlab_usage_ping_worker:ping', timeout: LEASE_TIMEOUT).try_obtain
|
|
|
|
end
|
|
|
|
end
|