From a107dc044d16b05a43f15ce531b1b631d78282d6 Mon Sep 17 00:00:00 2001 From: Vokhmin Alexey V Date: Tue, 5 Feb 2013 13:37:18 +0400 Subject: [PATCH 1/2] #889: update RpmWorkerObserver: restart build_list on failing --- lib/abf_worker/rpm_worker_observer.rb | 45 ++++++++++++++++++--------- 1 file changed, 30 insertions(+), 15 deletions(-) diff --git a/lib/abf_worker/rpm_worker_observer.rb b/lib/abf_worker/rpm_worker_observer.rb index bd08098b8..5ca55aaf8 100644 --- a/lib/abf_worker/rpm_worker_observer.rb +++ b/lib/abf_worker/rpm_worker_observer.rb @@ -1,33 +1,48 @@ module AbfWorker class RpmWorkerObserver < AbfWorker::BaseObserver + RESTARTED_BUILD_LISTS = 'abf-worker::rpm-worker-observer::restarted-build-lists' @queue = :rpm_worker_observer def self.perform(options) bl = BuildList.find options['id'] status = options['status'].to_i - item = find_or_create_item(bl) - fill_container_data(bl, options) if status != STARTED + unless restart_task(bl, status, options) + item = find_or_create_item(bl) + fill_container_data(bl, options) if status != STARTED - case status - when COMPLETED - bl.build_success - item.update_attributes({:status => BuildList::SUCCESS}) - bl.now_publish if bl.auto_publish? - when FAILED - bl.build_error - item.update_attributes({:status => BuildList::BUILD_ERROR}) - when STARTED - bl.start_build - when CANCELED - bl.build_canceled - item.update_attributes({:status => BuildList::BUILD_CANCELED}) + case status + when COMPLETED + bl.build_success + item.update_attributes({:status => BuildList::SUCCESS}) + bl.now_publish if bl.auto_publish? + when FAILED + bl.build_error + item.update_attributes({:status => BuildList::BUILD_ERROR}) + when STARTED + bl.start_build + when CANCELED + bl.build_canceled + item.update_attributes({:status => BuildList::BUILD_CANCELED}) + end end end class << self protected + def restart_task(bl, status, options) + redis = Resque.redis + if redis.lrem(RESTARTED_BUILD_LISTS, 0, bl.id) > 0 || status != FAILED || (options['results'] || []).size > 1 + return false + else + redis.lpush RESTARTED_BUILD_LISTS, bl.id + bl.update_column(:status, BuildList::BUILD_PENDING) + bl.add_job_to_abf_worker_queue + return true + end + end + def find_or_create_item(bl) bl.items.first || bl.items.create({ :version => bl.commit_hash, From 7898c8c47ea8e71ed88d4a2ffd782af00d57a4f7 Mon Sep 17 00:00:00 2001 From: Vokhmin Alexey V Date: Tue, 5 Feb 2013 14:29:12 +0400 Subject: [PATCH 2/2] #889: small refactoring --- lib/abf_worker/rpm_worker_observer.rb | 34 +++++++++++++-------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/lib/abf_worker/rpm_worker_observer.rb b/lib/abf_worker/rpm_worker_observer.rb index 5ca55aaf8..cc0167b88 100644 --- a/lib/abf_worker/rpm_worker_observer.rb +++ b/lib/abf_worker/rpm_worker_observer.rb @@ -7,24 +7,24 @@ module AbfWorker bl = BuildList.find options['id'] status = options['status'].to_i - unless restart_task(bl, status, options) - item = find_or_create_item(bl) - fill_container_data(bl, options) if status != STARTED + return if restart_task(bl, status, options) + + item = find_or_create_item(bl) + fill_container_data(bl, options) if status != STARTED - case status - when COMPLETED - bl.build_success - item.update_attributes({:status => BuildList::SUCCESS}) - bl.now_publish if bl.auto_publish? - when FAILED - bl.build_error - item.update_attributes({:status => BuildList::BUILD_ERROR}) - when STARTED - bl.start_build - when CANCELED - bl.build_canceled - item.update_attributes({:status => BuildList::BUILD_CANCELED}) - end + case status + when COMPLETED + bl.build_success + item.update_attributes({:status => BuildList::SUCCESS}) + bl.now_publish if bl.auto_publish? + when FAILED + bl.build_error + item.update_attributes({:status => BuildList::BUILD_ERROR}) + when STARTED + bl.start_build + when CANCELED + bl.build_canceled + item.update_attributes({:status => BuildList::BUILD_CANCELED}) end end