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,