diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-02-18 18:09:43 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-02-18 18:09:43 +0300 |
commit | 15714832c817685512f2ea1f2d91a94cb1cf67b9 (patch) | |
tree | e49977a709bba2a83cd30b92ea5578e1a99ba9ca /app/workers | |
parent | 213bd7e9d3d071e88f342511bdc48905b9d7e39c (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app/workers')
5 files changed, 92 insertions, 33 deletions
diff --git a/app/workers/all_queues.yml b/app/workers/all_queues.yml index 59ab0a4d05b..59c6b27e942 100644 --- a/app/workers/all_queues.yml +++ b/app/workers/all_queues.yml @@ -131,6 +131,14 @@ :weight: 1 :idempotent: true :tags: [] +- :name: cronjob:analytics_usage_trends_count_job_trigger + :feature_category: :devops_reports + :has_external_dependencies: + :urgency: :low + :resource_boundary: :unknown + :weight: 1 + :idempotent: true + :tags: [] - :name: cronjob:authorized_project_update_periodic_recalculate :feature_category: :source_code_management :has_external_dependencies: @@ -1413,6 +1421,14 @@ :weight: 1 :idempotent: true :tags: [] +- :name: analytics_usage_trends_counter_job + :feature_category: :devops_reports + :has_external_dependencies: + :urgency: :low + :resource_boundary: :unknown + :weight: 1 + :idempotent: true + :tags: [] - :name: approve_blocked_pending_approval_users :feature_category: :users :has_external_dependencies: diff --git a/app/workers/analytics/instance_statistics/count_job_trigger_worker.rb b/app/workers/analytics/instance_statistics/count_job_trigger_worker.rb index 81a765d5d08..3ec92bc7635 100644 --- a/app/workers/analytics/instance_statistics/count_job_trigger_worker.rb +++ b/app/workers/analytics/instance_statistics/count_job_trigger_worker.rb @@ -2,31 +2,19 @@ module Analytics module InstanceStatistics + # This worker will be removed in 14.0 class CountJobTriggerWorker include ApplicationWorker include CronjobQueue # rubocop:disable Scalability/CronWorkerContext - DEFAULT_DELAY = 3.minutes.freeze - feature_category :devops_reports urgency :low idempotent! def perform - recorded_at = Time.zone.now - - worker_arguments = Gitlab::Analytics::InstanceStatistics::WorkersArgumentBuilder.new( - measurement_identifiers: ::Analytics::InstanceStatistics::Measurement.measurement_identifier_values, - recorded_at: recorded_at - ).execute - - perform_in = DEFAULT_DELAY.minutes.from_now - worker_arguments.each do |args| - CounterJobWorker.perform_in(perform_in, *args) - - perform_in += DEFAULT_DELAY - end + # Delegate to the new worker + Analytics::UsageTrends::CountJobTriggerWorker.new.perform end end end diff --git a/app/workers/analytics/instance_statistics/counter_job_worker.rb b/app/workers/analytics/instance_statistics/counter_job_worker.rb index c07b2569453..4beed8a3e2f 100644 --- a/app/workers/analytics/instance_statistics/counter_job_worker.rb +++ b/app/workers/analytics/instance_statistics/counter_job_worker.rb @@ -2,6 +2,7 @@ module Analytics module InstanceStatistics + # This worker will be removed in 14.0 class CounterJobWorker include ApplicationWorker @@ -10,24 +11,9 @@ module Analytics idempotent! - def perform(measurement_identifier, min_id, max_id, recorded_at) - query_scope = ::Analytics::InstanceStatistics::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 - - InstanceStatistics::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) + def perform(*args) + # Delegate to the new worker + Analytics::UsageTrends::CounterJobWorker.new.perform(*args) end end end diff --git a/app/workers/analytics/usage_trends/count_job_trigger_worker.rb b/app/workers/analytics/usage_trends/count_job_trigger_worker.rb new file mode 100644 index 00000000000..37f5c19d64c --- /dev/null +++ b/app/workers/analytics/usage_trends/count_job_trigger_worker.rb @@ -0,0 +1,34 @@ +# frozen_string_literal: true + +module Analytics + module UsageTrends + class CountJobTriggerWorker + extend ::Gitlab::Utils::Override + include ApplicationWorker + include CronjobQueue # rubocop:disable Scalability/CronWorkerContext + + DEFAULT_DELAY = 3.minutes.freeze + + feature_category :devops_reports + urgency :low + + idempotent! + + def perform + recorded_at = Time.zone.now + + worker_arguments = Gitlab::Analytics::UsageTrends::WorkersArgumentBuilder.new( + measurement_identifiers: ::Analytics::UsageTrends::Measurement.measurement_identifier_values, + recorded_at: recorded_at + ).execute + + perform_in = DEFAULT_DELAY.minutes.from_now + worker_arguments.each do |args| + CounterJobWorker.perform_in(perform_in, *args) + + perform_in += DEFAULT_DELAY + end + end + end + end +end diff --git a/app/workers/analytics/usage_trends/counter_job_worker.rb b/app/workers/analytics/usage_trends/counter_job_worker.rb new file mode 100644 index 00000000000..275c6ac2de2 --- /dev/null +++ b/app/workers/analytics/usage_trends/counter_job_worker.rb @@ -0,0 +1,35 @@ +# frozen_string_literal: true + +module Analytics + module UsageTrends + class CounterJobWorker + extend ::Gitlab::Utils::Override + include ApplicationWorker + + feature_category :devops_reports + urgency :low + + 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 |