Commit 7ed7ca8c authored by Tiago Botelho's avatar Tiago Botelho

Refactors Project Destroy service and worker code

parent c3b244a8
...@@ -26,28 +26,15 @@ module Projects ...@@ -26,28 +26,15 @@ module Projects
Projects::UnlinkForkService.new(project, current_user).execute Projects::UnlinkForkService.new(project, current_user).execute
Project.transaction do attempt_destroy_transaction(project, repo_path, wiki_path)
unless remove_legacy_registry_tags
raise_error('Failed to remove some tags in project container registry. Please try again or contact administrator.')
end
unless remove_repository(repo_path)
raise_error('Failed to remove project repository. Please try again or contact administrator.')
end
unless remove_repository(wiki_path)
raise_error('Failed to remove wiki repository. Please try again or contact administrator.')
end
project.team.truncate
project.destroy!
trash_repositories!
end
system_hook_service.execute_hooks_for(project, :destroy) system_hook_service.execute_hooks_for(project, :destroy)
log_info("Project \"#{project.full_path}\" was removed") log_info("Project \"#{project.full_path}\" was removed")
true true
rescue Projects::DestroyService::DestroyError => error
Rails.logger.error("Deletion failed on #{project.full_path} with the following message: #{error.message}")
false
end end
private private
...@@ -91,6 +78,22 @@ module Projects ...@@ -91,6 +78,22 @@ module Projects
end end
end end
def attempt_destroy_transaction(project, repo_path, wiki_path)
Project.transaction do
unless remove_legacy_registry_tags
raise_error('Failed to remove some tags in project container registry. Please try again or contact administrator.')
end
trash_repositories!
project.team.truncate
project.destroy!
end
rescue Exception => error # rubocop:disable Lint/RescueException
project.update_attributes(delete_error: error.message, pending_delete: false)
raise
end
## ##
# This method makes sure that we correctly remove registry tags # This method makes sure that we correctly remove registry tags
# for legacy image repository (when repository path equals project path). # for legacy image repository (when repository path equals project path).
......
...@@ -7,10 +7,7 @@ class ProjectDestroyWorker ...@@ -7,10 +7,7 @@ class ProjectDestroyWorker
user = User.find(user_id) user = User.find(user_id)
::Projects::DestroyService.new(project, user, params.symbolize_keys).execute ::Projects::DestroyService.new(project, user, params.symbolize_keys).execute
rescue Exception => error # rubocop:disable Lint/RescueException rescue ActiveRecord::RecordNotFound => error
project&.update_attributes(delete_error: error.message, pending_delete: false) logger.error("Failed to delete project #{project.path_with_namespace} (#{project.id}): #{error.message}")
Rails.logger.error("Deletion failed on #{project&.full_path} with the following message: #{error.message}")
raise
end end
end end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment