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.

55 lines
1.8 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
2022-10-11 01:57:18 +05:30
def perform(options = {})
# Sidekiq does not support keyword arguments, so the args need to be
# passed the old pre-Ruby 2.0 way.
#
# See https://github.com/mperham/sidekiq/issues/2372
triggered_from_cron = options.fetch('triggered_from_cron', true)
skip_db_write = options.fetch('skip_db_write', false)
# Disable service ping for GitLab.com unless called manually
2021-02-22 17:27:13 +05:30
# See https://gitlab.com/gitlab-org/gitlab/-/issues/292929 for details
2022-10-11 01:57:18 +05:30
return if Gitlab.com? && triggered_from_cron
2021-02-22 17:27:13 +05:30
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-10-11 01:57:18 +05:30
ServicePing::SubmitService.new(payload: usage_data, skip_db_write: skip_db_write).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