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

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

48 lines
1.4 KiB
Ruby
Raw Normal View History

2018-11-08 19:23:39 +05:30
# frozen_string_literal: true
2021-09-30 23:02:18 +05:30
class GitlabServicePingWorker # rubocop:disable Scalability/IdempotentWorker
LEASE_KEY = 'gitlab_service_ping_worker:ping'
2017-08-17 22:00:37 +05:30
LEASE_TIMEOUT = 86400
2018-03-17 18:26:18 +05:30
include ApplicationWorker
2021-10-27 15:23:28 +05:30
data_consistency :always
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-09-30 23:02:18 +05:30
feature_category :service_ping
2021-10-27 15:23:28 +05:30
worker_resource_boundary :cpu
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-09-30 23:02:18 +05:30
# Disable service ping for GitLab.com
2021-02-22 17:27:13 +05:30
# 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
2022-07-23 23:45:48 +05:30
ServicePing::SubmitService.new(payload: usage_data).execute
2020-10-24 23:57:45 +05:30
end
2017-08-17 22:00:37 +05:30
end
2022-07-23 23:45:48 +05:30
def usage_data
ServicePing::BuildPayload.new.execute.tap do |payload|
record = {
recorded_at: payload[:recorded_at],
payload: payload,
created_at: Time.current,
updated_at: Time.current
}
RawUsageData.upsert(record, unique_by: :recorded_at)
end
rescue StandardError => err
Gitlab::ErrorTracking.track_and_raise_for_dev_exception(err)
nil
end
2017-08-17 22:00:37 +05:30
end