rosa-build/lib/abf_worker/rpm_worker_observer.rb

72 lines
2.0 KiB
Ruby
Raw Normal View History

2012-11-26 18:00:29 +00:00
module AbfWorker
2012-12-11 15:25:25 +00:00
class RpmWorkerObserver < AbfWorker::BaseObserver
RESTARTED_BUILD_LISTS = 'abf-worker::rpm-worker-observer::restarted-build-lists'
2012-11-26 18:00:29 +00:00
@queue = :rpm_worker_observer
def self.perform(options)
new(options, BuildList).perform
end
def perform
2013-02-06 10:54:12 +00:00
return if restart_task
2012-12-11 16:56:17 +00:00
2013-02-06 10:54:12 +00:00
item = find_or_create_item
fill_container_data if status != STARTED
2012-12-11 16:56:17 +00:00
case status
2012-12-13 12:30:37 +00:00
when COMPLETED
subject.build_success
subject.now_publish if subject.auto_publish?
2012-12-13 12:30:37 +00:00
when FAILED
subject.build_error
2013-01-24 11:32:00 +00:00
item.update_attributes({:status => BuildList::BUILD_ERROR})
2012-12-13 12:30:37 +00:00
when STARTED
subject.start_build
2012-12-13 12:30:37 +00:00
when CANCELED
subject.build_canceled
item.update_attributes({:status => BuildList::BUILD_CANCELED})
when TESTS_FAILED
subject.tests_failed
2012-11-26 18:00:29 +00:00
end
item.update_attributes({:status => BuildList::SUCCESS}) if [TESTS_FAILED, COMPLETED].include?(status)
end
protected
def find_or_create_item
subject.items.first || subject.items.create({
:version => subject.commit_hash,
:name => subject.project.name,
:status => BuildList::BUILD_STARTED,
:level => 0
})
end
2013-02-06 10:54:12 +00:00
def restart_task
return false if status != FAILED
2013-02-06 10:54:12 +00:00
redis = Resque.redis
if redis.lrem(RESTARTED_BUILD_LISTS, 0, subject.id) > 0 || (options['results'] || []).size > 1
2013-02-06 10:54:12 +00:00
return false
else
redis.lpush RESTARTED_BUILD_LISTS, subject.id
subject.update_column(:status, BuildList::BUILD_PENDING)
subject.add_job_to_abf_worker_queue
return true
end
2013-02-06 10:54:12 +00:00
end
def fill_container_data
2013-02-06 14:23:40 +00:00
(options['packages'] || []).each do |package|
package = subject.packages.build(package)
package.package_type = package['fullname'] =~ /.*\.src\.rpm$/ ? 'source' : 'binary'
package.project_id = subject.project_id
package.platform_id = subject.save_to_platform_id
package.save!
end
update_results
2012-11-26 18:00:29 +00:00
end
end
end