Class: Analytics::UsageTrends::CounterJobWorker

Inherits:
Object
  • Object
show all
Extended by:
Gitlab::Utils::Override
Includes:
ApplicationWorker
Defined in:
app/workers/analytics/usage_trends/counter_job_worker.rb

Constant Summary collapse

TIMEOUT =
250.seconds

Constants included from ApplicationWorker

ApplicationWorker::LOGGING_EXTRA_KEY, ApplicationWorker::SAFE_PUSH_BULK_LIMIT

Constants included from Gitlab::Loggable

Gitlab::Loggable::ANONYMOUS

Constants included from WorkerAttributes

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::Utils::Override

extended, extensions, included, method_added, override, prepended, queue_verification, verify!

Methods included from Gitlab::Loggable

#build_structured_payload

Methods included from Gitlab::SidekiqVersioning::Worker

#job_version

Methods included from WorkerContext

#with_context

Instance Method Details

#perform(measurement_identifier, min_id, max_id, recorded_at, partial_results = nil) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'app/workers/analytics/usage_trends/counter_job_worker.rb', line 20

def perform(measurement_identifier, min_id, max_id, recorded_at, partial_results = nil)
  query_scope = ::Analytics::UsageTrends::Measurement.identifier_query_mapping[measurement_identifier].call

  result = counter(query_scope, min_id, max_id, partial_results)

  # If the batch counter timed out, schedule a job to continue counting later
  if result[:status] == :timeout
    return self.class.perform_async(measurement_identifier, result[:continue_from], max_id, recorded_at, result[:partial_results])
  end

  return if result[:status] != :completed

  UsageTrends::Measurement.insert_all([{ recorded_at: recorded_at, count: result[:count], identifier: measurement_identifier }])
end