Skip to content
Snippets Groups Projects

Phase 2 enqueuer

Merged Steve Abrams requested to merge 349744-phase2-enqueuer into master
All threads resolved!
Compare and Show latest version
9 files
+ 86
59
Compare changes
  • Side-by-side
  • Inline
Files
9
@@ -5,6 +5,7 @@ class ContainerRepository < ApplicationRecord
include Gitlab::SQL::Pattern
include EachBatch
include Sortable
include AfterCommitQueue
WAITING_CLEANUP_STATUSES = %i[cleanup_scheduled cleanup_unfinished].freeze
REQUIRING_CLEANUP_STATUSES = %i[cleanup_unscheduled cleanup_scheduled].freeze
@@ -48,7 +49,11 @@ class ContainerRepository < ApplicationRecord
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 :recently_imported, -> { where(migration_state: :import_done).order(:migration_import_done_at) }
scope :recently_done_migration_step, -> do
where(migration_state: %w[import_done pre_import_done import_aborted])
.order(Arel.sql('GREATEST(migration_pre_import_done_at, migration_import_done_at, migration_aborted_at) DESC'))
end
scope :ready_for_import, -> do
# There is no yaml file for the container_registry_phase_2_deny_list
@@ -70,7 +75,7 @@ class ContainerRepository < ApplicationRecord
)
end
state_machine :migration_state, initial: :default, use_transactions: false do
state_machine :migration_state, initial: :default do
state :pre_importing do
validates :migration_pre_import_started_at, presence: true
validates :migration_pre_import_done_at, presence: false
@@ -180,6 +185,12 @@ class ContainerRepository < ApplicationRecord
before_transition any => :import_skipped do |container_repository|
container_repository.migration_skipped_at = Time.zone.now
end
before_transition any => %i[import_done import_aborted] do |container_repository|
container_repository.run_after_commit do
::ContainerRegistry::Migration::EnqueuerWorker.perform_async
end
end
end
def self.exists_by_path?(path)
@@ -242,26 +253,6 @@ def finish_pre_import_and_start_import
finish_pre_import && start_import
end
def abort_import
# workers cannot be called from within the transaction so we call
# it separately here instead of using callbacks
result = super
::ContainerRegistry::Migration::EnqueuerWorker.perform_async
result
end
def finish_import
# workers cannot be called from within the transaction so we call
# it separately here instead of using callbacks
result = super
::ContainerRegistry::Migration::EnqueuerWorker.perform_async
result
end
def retry_migration
return if migration_import_done_at
@@ -293,6 +284,10 @@ def try_import
end
end
def last_import_step_done_at
[migration_pre_import_done_at, migration_import_done_at, migration_aborted_at].compact.max
end
# rubocop: disable CodeReuse/ServiceClass
def registry
@registry ||= begin
Loading