2021-02-18 15:09:43 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Analytics
|
|
|
|
module UsageTrends
|
|
|
|
class CounterJobWorker
|
|
|
|
extend ::Gitlab::Utils::Override
|
|
|
|
include ApplicationWorker
|
|
|
|
|
2021-04-30 18:10:09 +00:00
|
|
|
sidekiq_options retry: 3
|
|
|
|
|
2021-02-18 15:09:43 +00:00
|
|
|
feature_category :devops_reports
|
|
|
|
urgency :low
|
2021-05-03 09:10:02 +00:00
|
|
|
tags :exclude_from_kubernetes
|
2021-02-18 15:09:43 +00:00
|
|
|
|
|
|
|
idempotent!
|
|
|
|
|
|
|
|
def perform(measurement_identifier, min_id, max_id, recorded_at)
|
|
|
|
query_scope = ::Analytics::UsageTrends::Measurement.identifier_query_mapping[measurement_identifier].call
|
|
|
|
|
|
|
|
count = if min_id.nil? || max_id.nil? # table is empty
|
|
|
|
0
|
|
|
|
else
|
|
|
|
counter(query_scope, min_id, max_id)
|
|
|
|
end
|
|
|
|
|
|
|
|
return if count == Gitlab::Database::BatchCounter::FALLBACK
|
|
|
|
|
|
|
|
UsageTrends::Measurement.insert_all([{ recorded_at: recorded_at, count: count, identifier: measurement_identifier }])
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def counter(query_scope, min_id, max_id)
|
|
|
|
Gitlab::Database::BatchCount.batch_count(query_scope, start: min_id, finish: max_id)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|