#889: update RpmWorkerObserver: restart build_list on failing

This commit is contained in:
Vokhmin Alexey V 2013-02-05 13:37:18 +04:00
parent 53e4ab573f
commit a107dc044d
1 changed files with 30 additions and 15 deletions

View File

@ -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,