diff options
author | Robert Speicher <robert@gitlab.com> | 2018-09-07 20:26:51 +0000 |
---|---|---|
committer | Robert Speicher <robert@gitlab.com> | 2018-09-07 20:26:51 +0000 |
commit | c014f7fd4ce82e9b4a907eab3915702053f0557f (patch) | |
tree | 299f39775865394977fce10b5caaf16a781c994e /app/workers | |
parent | 9d895a73d4e2a034a6bbf6389d12fda1baba888f (diff) | |
parent | 5830d1143dbf6b2958153233279896961e9a44df (diff) | |
download | gitlab-ce-c014f7fd4ce82e9b4a907eab3915702053f0557f.tar.gz |
Merge branch 'sh-delete-container-registry-async' into 'master'
Delete a container registry asynchronously
Closes #51063 and #49926
See merge request gitlab-org/gitlab-ce!21553
Diffstat (limited to 'app/workers')
-rw-r--r-- | app/workers/all_queues.yml | 1 | ||||
-rw-r--r-- | app/workers/delete_container_repository_worker.rb | 34 |
2 files changed, 35 insertions, 0 deletions
diff --git a/app/workers/all_queues.yml b/app/workers/all_queues.yml index ae9dc8d4857..1eeb972cee9 100644 --- a/app/workers/all_queues.yml +++ b/app/workers/all_queues.yml @@ -87,6 +87,7 @@ - authorized_projects - background_migration - create_gpg_signature +- delete_container_repository - delete_merged_branches - delete_user - email_receiver diff --git a/app/workers/delete_container_repository_worker.rb b/app/workers/delete_container_repository_worker.rb new file mode 100644 index 00000000000..b703530d3a0 --- /dev/null +++ b/app/workers/delete_container_repository_worker.rb @@ -0,0 +1,34 @@ +# frozen_string_literal: true + +class DeleteContainerRepositoryWorker + include ApplicationWorker + include ExclusiveLeaseGuard + + LEASE_TIMEOUT = 1.hour + + attr_reader :container_repository + + def perform(current_user_id, container_repository_id) + current_user = User.find_by(id: current_user_id) + @container_repository = ContainerRepository.find_by(id: container_repository_id) + project = container_repository&.project + + return unless current_user && container_repository && project + + # If a user accidentally attempts to delete the same container registry in quick succession, + # this can lead to orphaned tags. + try_obtain_lease do + Projects::ContainerRepository::DestroyService.new(project, current_user).execute(container_repository) + end + end + + # For ExclusiveLeaseGuard concern + def lease_key + @lease_key ||= "container_repository:delete:#{container_repository.id}" + end + + # For ExclusiveLeaseGuard concern + def lease_timeout + LEASE_TIMEOUT + end +end |