Class: GitlabServicePingWorker
- Inherits:
-
Object
- Object
- GitlabServicePingWorker
- Defined in:
- app/workers/gitlab_service_ping_worker.rb
Overview
rubocop:disable Scalability/IdempotentWorker
Constant Summary collapse
- LEASE_KEY =
'gitlab_service_ping_worker:ping'- NON_SQL_LEASE_KEY =
'gitlab_service_ping_worker:non_sql_ping'- QUERIES_LEASE_KEY =
'gitlab_service_ping_worker:queries_ping'- LEASE_TIMEOUT =
86400
Constants included from Gitlab::ExclusiveLeaseHelpers
Gitlab::ExclusiveLeaseHelpers::FailedToObtainLockError
Constants included from ApplicationWorker
ApplicationWorker::LOGGING_EXTRA_KEY, ApplicationWorker::SAFE_PUSH_BULK_LIMIT
Constants included from Gitlab::Loggable
Constants included from WorkerAttributes
WorkerAttributes::DEFAULT_CONCURRENCY_LIMIT_PERCENTAGE_BY_URGENCY, WorkerAttributes::DEFAULT_DATA_CONSISTENCY, WorkerAttributes::DEFAULT_DATA_CONSISTENCY_PER_DB, WorkerAttributes::DEFAULT_DEFER_DELAY, WorkerAttributes::LOAD_BALANCED_DATA_CONSISTENCIES, WorkerAttributes::NAMESPACE_WEIGHTS, WorkerAttributes::VALID_DATA_CONSISTENCIES, WorkerAttributes::VALID_RESOURCE_BOUNDARIES, WorkerAttributes::VALID_URGENCIES
Instance Method Summary collapse
Methods included from Gitlab::ExclusiveLeaseHelpers
Methods included from Gitlab::Loggable
Methods included from Gitlab::SidekiqVersioning::Worker
Methods included from WorkerContext
Instance Method Details
#perform(options = {}) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'app/workers/gitlab_service_ping_worker.rb', line 20 def perform( = {}) return unless ::Gitlab::CurrentSettings.usage_ping_generation_enabled? organization = Organizations::Organization.first day_lock(NON_SQL_LEASE_KEY) do save_non_sql_data(organization) end day_lock(QUERIES_LEASE_KEY) do save_queries_data(organization) end # 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 = .fetch('triggered_from_cron', true) # Disable service ping for GitLab.com unless called manually # See https://gitlab.com/gitlab-org/gitlab/-/issues/292929 for details return if Gitlab.com? && triggered_from_cron day_lock(LEASE_KEY) do ServicePing::SubmitService.new(organization: organization, payload: usage_data(organization)).execute end end |
#usage_data(organization) ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'app/workers/gitlab_service_ping_worker.rb', line 48 def usage_data(organization) ServicePing::BuildPayload.new.execute.tap do |payload| record = { recorded_at: payload[:recorded_at], payload: payload, created_at: Time.current, updated_at: Time.current, organization_id: organization.id } RawUsageData.upsert(record, unique_by: [:organization_id, :recorded_at]) end rescue StandardError => err Gitlab::ErrorTracking.track_and_raise_for_dev_exception(err) nil end |