From c159146048ce4512e3e0b80c6cb34ad40f623bb1 Mon Sep 17 00:00:00 2001 From: Vokhmin Alexey V Date: Mon, 17 Dec 2012 18:39:02 +0400 Subject: [PATCH] #778: add #destroy_project_from_repository method --- app/models/project.rb | 47 +++++++++++++++++++++++++++++ app/models/project_to_repository.rb | 3 +- 2 files changed, 49 insertions(+), 1 deletion(-) diff --git a/app/models/project.rb b/app/models/project.rb index 6325616e9..c9b6b80be 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -185,8 +185,55 @@ class Project < ActiveRecord::Base end end + def destroy_project_from_repository(repository) + platform = repository.platform + published_packages = build_lists.for_status(BuildList::BUILD_PUBLISHED). + scoped_to_save_platform(platform.id) + if platform.personal? + Platform.main.each do |main_platform| + add_job_to_abf_worker_queue( + repository, + main_platform.distrib_type, + published_packages.for_platform(main_platform.id), + "#{platform.path}/repository/#{main_platform.name}" + ) + end + else + add_job_to_abf_worker_queue( + repository, + platform.distrib_type, + published_packages, + "#{platform.path}/repository" + ) + end + end + later :destroy_project_from_repository, :queue => :clone_build + protected + def add_job_to_abf_worker_queue(repository, type, packages, platform_path) + Arch.all.each do |arch| + packages = packages.scoped_to_arch(arch.id). + includes(:packages).last(10). + map{ |bl| bl.packages.pluck(:fullname) }.flatten + Resque.push( + "publish_build_list_container_#{type}_worker", + 'class' => "AbfWorker::PublishBuildListContainer#{type.capitalize}Worker", + 'args' => [{ + :id => repository.id, + :arch => arch.name, + :distrib_type => type, + :packages => packages, + :platform => { + :platform_path => platform_path + }, + :repository_name => repository.name, + :time_living => 2400 # 40 min + }] + ) + end + end + def truncate_name self.name = name.strip if name end diff --git a/app/models/project_to_repository.rb b/app/models/project_to_repository.rb index 611bb0bbe..a9bce258a 100644 --- a/app/models/project_to_repository.rb +++ b/app/models/project_to_repository.rb @@ -6,7 +6,8 @@ class ProjectToRepository < ActiveRecord::Base delegate :path, :to => :project after_create lambda { project.xml_rpc_create(repository) }, :unless => lambda {Thread.current[:skip]} - after_destroy lambda { project.xml_rpc_destroy(repository) }, :unless => lambda {Thread.current[:skip]} + after_destroy lambda { project.destroy_project_from_repository(repository) } + # after_destroy lambda { project.xml_rpc_destroy(repository) }, :unless => lambda {Thread.current[:skip]} # after_rollback lambda { project.xml_rpc_destroy(repository) rescue true if new_record? } validate :one_project_in_platform_repositories