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
Projects::UnlinkForkService.new(project, current_user).execute
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
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
attempt_destroy_transaction(project, repo_path, wiki_path)
system_hook_service.execute_hooks_for(project, :destroy)
log_info("Project \"#{project.full_path}\" was removed")
true
rescue Projects::DestroyService::DestroyError => error
Rails.logger.error("Deletion failed on #{project.full_path} with the following message: #{error.message}")
false
end
private
......@@ -91,6 +78,22 @@ module Projects
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
# for legacy image repository (when repository path equals project path).
......
......@@ -7,10 +7,7 @@ class ProjectDestroyWorker
user = User.find(user_id)
::Projects::DestroyService.new(project, user, params.symbolize_keys).execute
rescue Exception => error # rubocop:disable Lint/RescueException
project&.update_attributes(delete_error: error.message, pending_delete: false)
Rails.logger.error("Deletion failed on #{project&.full_path} with the following message: #{error.message}")
raise
rescue ActiveRecord::RecordNotFound => error
logger.error("Failed to delete project #{project.path_with_namespace} (#{project.id}): #{error.message}")
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