debian-mirror-gitlab/app/workers/gitlab_usage_ping_worker.rb

33 lines
865 B
Ruby
Raw Normal View History

2018-11-08 19:23:39 +05:30
# frozen_string_literal: true
2017-08-17 22:00:37 +05:30
class GitlabUsagePingWorker
LEASE_TIMEOUT = 86400
2018-03-17 18:26:18 +05:30
include ApplicationWorker
2020-03-13 15:44:24 +05:30
# rubocop:disable Scalability/CronWorkerContext
# This worker does not perform work scoped to a context
2017-08-17 22:00:37 +05:30
include CronjobQueue
2020-03-13 15:44:24 +05:30
# rubocop:enable Scalability/CronWorkerContext
2017-08-17 22:00:37 +05:30
2019-12-21 20:55:43 +05:30
feature_category_not_owned!
2019-10-12 21:52:04 +05:30
# Retry for up to approximately three hours then give up.
sidekiq_options retry: 10, dead: false
2017-08-17 22:00:37 +05:30
def perform
# Multiple Sidekiq workers could run this. We should only do this at most once a day.
return unless try_obtain_lease
2019-10-12 21:52:04 +05:30
# 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
SubmitUsagePingService.new.execute
2017-08-17 22:00:37 +05:30
end
2017-09-10 17:25:29 +05:30
private
2017-08-17 22:00:37 +05:30
def try_obtain_lease
Gitlab::ExclusiveLease.new('gitlab_usage_ping_worker:ping', timeout: LEASE_TIMEOUT).try_obtain
end
end