Skip to content
Snippets Groups Projects

Phase 2 enqueuer

Merged Steve Abrams requested to merge 349744-phase2-enqueuer into master
2 files
+ 45
52
Compare changes
  • Side-by-side
  • Inline
Files
2
@@ -30,6 +30,7 @@ class ContainerRepository < ApplicationRecord
delegate :client, :gitlab_api_client, to: :registry
scope :ordered, -> { order(:name) }
scope :unordered, -> { order('') }
scope :with_api_entity_associations, -> { preload(project: [:route, { namespace: :route }]) }
scope :for_group_and_its_subgroups, ->(group) do
project_scope = Project
@@ -44,6 +45,27 @@ class ContainerRepository < ApplicationRecord
scope :waiting_for_cleanup, -> { where(expiration_policy_cleanup_status: WAITING_CLEANUP_STATUSES) }
scope :expiration_policy_started_at_nil_or_before, ->(timestamp) { where('expiration_policy_started_at < ? OR expiration_policy_started_at IS NULL', timestamp) }
scope :with_stale_ongoing_cleanup, ->(threshold) { cleanup_ongoing.where('expiration_policy_started_at < ?', threshold) }
scope :import_in_process, -> { where(migration_state: %w[pre_importing pre_import_done importing]) }
scope :aborted_imports, -> { where(migration_state: :import_aborted).unordered }
scope :recently_imported, -> { where(migration_state: :import_done).order(:migration_import_done_at) }
scope :ready_for_import, -> do
joins(
project: [namespace: [gitlab_subscription: [:hosted_plan]]]
).where(
migration_state: [:default],
created_at: ...ContainerRegistry::Migration.created_before,
plans: { name: ContainerRegistry::Migration.target_plan }
).where(
"NOT EXISTS (
SELECT 1
FROM feature_gates
WHERE feature_gates.feature_key = 'container_registry_phase_2_deny_list'
AND feature_gates.key = 'actors'
AND feature_gates.value = concat('Group:', projects.namespace_id)
)"
).unordered
end
state_machine :migration_state, initial: :default do
state :pre_importing do
@@ -153,13 +175,7 @@ class ContainerRepository < ApplicationRecord
end
before_transition any => %i[import_done import_aborted] do
if Feature.enabled(:container_registry_migration_phase2_enqueue_speed_slow)
ContainerRegistry::Import::EnqueuerWorker.perform_in(10.minutes)
elsif Feature.enabled(:container_registry_migration_phase2_enqueue_speed_fast)
ContainerRegistry::Import::EnqueuerWorker.perform_async
end
# To be implemented in https://gitlab.com/gitlab-org/gitlab/-/issues/349744
::ContainerRegistry::Import::EnqueuerWorker.perform_async
end
end
Loading