Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'app/workers/container_registry/migration/observer_worker.rb')
-rw-r--r--app/workers/container_registry/migration/observer_worker.rb40
1 files changed, 40 insertions, 0 deletions
diff --git a/app/workers/container_registry/migration/observer_worker.rb b/app/workers/container_registry/migration/observer_worker.rb
new file mode 100644
index 00000000000..757c4fd11a5
--- /dev/null
+++ b/app/workers/container_registry/migration/observer_worker.rb
@@ -0,0 +1,40 @@
+# frozen_string_literal: true
+
+module ContainerRegistry
+ module Migration
+ class ObserverWorker
+ include ApplicationWorker
+ # This worker does not perform work scoped to a context
+ include CronjobQueue # rubocop:disable Scalability/CronWorkerContext
+
+ COUNT_BATCH_SIZE = 50000
+
+ data_consistency :sticky
+ feature_category :container_registry
+ urgency :low
+ deduplicate :until_executed, including_scheduled: true
+ idempotent!
+
+ def perform
+ return unless ::ContainerRegistry::Migration.enabled?
+
+ use_replica_if_available do
+ ContainerRepository::MIGRATION_STATES.each do |state|
+ relation = ContainerRepository.with_migration_state(state)
+ count = ::Gitlab::Database::BatchCount.batch_count(
+ relation, batch_size: COUNT_BATCH_SIZE
+ )
+ name = "#{state}_count".to_sym
+ log_extra_metadata_on_done(name, count)
+ end
+ end
+ end
+
+ private
+
+ def use_replica_if_available(&block)
+ ::Gitlab::Database::LoadBalancing::Session.current.use_replicas_for_read_queries(&block)
+ end
+ end
+ end
+end