From 73b769aeb5c6a922d45561e4a9f5846ac4b5ea65 Mon Sep 17 00:00:00 2001 From: Vokhmin Alexey V Date: Sat, 12 Jan 2013 21:18:13 +0400 Subject: [PATCH] #823: update PublishObserver --- .../build_lists_publish_task_manager.rb | 18 +++++++++++-- lib/abf_worker/publish_observer.rb | 27 ++++++++++--------- 2 files changed, 30 insertions(+), 15 deletions(-) diff --git a/lib/abf_worker/build_lists_publish_task_manager.rb b/lib/abf_worker/build_lists_publish_task_manager.rb index 78fa3732d..f977f1afa 100644 --- a/lib/abf_worker/build_lists_publish_task_manager.rb +++ b/lib/abf_worker/build_lists_publish_task_manager.rb @@ -33,6 +33,15 @@ module AbfWorker end end + def self.unlock_build_list(build_list) + Resque.redis.lrem(LOCKED_BUILD_LISTS, 0, build_list.id) + end + + def self.unlock_rep_and_platform(build_list) + key = "#{build_list.save_to_repository_id}-#{build_list.build_for_platform_id}" + Resque.redis.lrem(LOCKED_REP_AND_PLATFORMS, 0, key) + end + private def create_task(save_to_repository_id, build_for_platform_id) @@ -71,20 +80,25 @@ module AbfWorker packages = {:sources => [], :binaries => {:x86_64 => [], :i586 => []}} old_packages = packages.clone + build_list_ids = [] build_lists.each do |bl| fill_packages(bl, packages) bl.last_published.includes(:packages).limit(5).each{ |old_bl| fill_packages(old_bl, old_packages) } + build_list_ids << bl.id @redis.lpush(LOCKED_BUILD_LISTS, bl.id) end - options.merge!({:packages => packages, :old_packages => old_packages}) Resque.push( worker_queue, 'class' => worker_class, - 'args' => [options] + 'args' => [options.merge({ + :packages => packages, + :old_packages => old_packages, + :build_list_ids => build_list_ids + })] ) return true end diff --git a/lib/abf_worker/publish_observer.rb b/lib/abf_worker/publish_observer.rb index 59bf86866..c3f9d1653 100644 --- a/lib/abf_worker/publish_observer.rb +++ b/lib/abf_worker/publish_observer.rb @@ -3,26 +3,27 @@ module AbfWorker @queue = :publish_observer def self.perform(options) - bl = BuildList.find options['id'] + build_lists = BuildList.where(:id => options['build_list_ids']) status = options['status'].to_i - case status - when COMPLETED - bl.published - update_results(bl, options) - when FAILED - bl.fail_publish - update_results(bl, options) - when CANCELED - bl.fail_publish + build_lists.each do |bl| update_results(bl, options) + case status + when COMPLETED + bl.published + when FAILED + bl.fail_publish + when CANCELED + bl.fail_publish + end + AbfWorker::BuildListsPublishTaskManager.unlock_build_list bl end + AbfWorker::BuildListsPublishTaskManager.unlock_rep_and_platform build_lists.first end def self.update_results(subject, options) results = (subject.results || []). - map{ |r| r if r['file_name'] !~ /^abfworker\:\:publish\-worker.*\.log$/ }. - compact - results += options['results'] + select{ |r| r['file_name'] !~ /^abfworker\:\:publish\-worker.*\.log$/ } + results |= options['results'] sort_results_and_save(subject, results) end