diff options
Diffstat (limited to 'app/workers/delete_container_repository_worker.rb')
-rw-r--r-- | app/workers/delete_container_repository_worker.rb | 37 |
1 files changed, 35 insertions, 2 deletions
diff --git a/app/workers/delete_container_repository_worker.rb b/app/workers/delete_container_repository_worker.rb index a4d6adc2195..73e6843fdd0 100644 --- a/app/workers/delete_container_repository_worker.rb +++ b/app/workers/delete_container_repository_worker.rb @@ -2,16 +2,17 @@ class DeleteContainerRepositoryWorker # rubocop:disable Scalability/IdempotentWorker include ApplicationWorker + include ExclusiveLeaseGuard data_consistency :always sidekiq_options retry: 3 - include ExclusiveLeaseGuard queue_namespace :container_repository feature_category :container_registry - LEASE_TIMEOUT = 1.hour + LEASE_TIMEOUT = 1.hour.freeze + FIXED_DELAY = 10.seconds.freeze attr_reader :container_repository @@ -22,6 +23,16 @@ class DeleteContainerRepositoryWorker # rubocop:disable Scalability/IdempotentWo return unless current_user && container_repository && project + if migration.delete_container_repository_worker_support? && migrating? + delay = migration_duration + + self.class.perform_in(delay.from_now) + + log_extra_metadata_on_done(:delete_postponed, delay) + + return + end + # If a user accidentally attempts to delete the same container registry in quick succession, # this can lead to orphaned tags. try_obtain_lease do @@ -29,6 +40,28 @@ class DeleteContainerRepositoryWorker # rubocop:disable Scalability/IdempotentWo end end + private + + def migrating? + !(container_repository.default? || + container_repository.import_done? || + container_repository.import_skipped?) + end + + def migration_duration + duration = migration.import_timeout.seconds + FIXED_DELAY + + if container_repository.pre_importing? + duration += migration.dynamic_pre_import_timeout_for(container_repository) + end + + duration + end + + def migration + ContainerRegistry::Migration + end + # For ExclusiveLeaseGuard concern def lease_key @lease_key ||= "container_repository:delete:#{container_repository.id}" |