提交 0aa8249e 编写于 作者: T Tiago Botelho

Refactors Project Destroy service and worker code

上级 3491b19a
......@@ -25,27 +25,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!
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
......@@ -71,6 +59,28 @@ 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
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!
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% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册