rosa-build/lib/abf_worker/rpm_worker_observer.rb

54 lines
1.5 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
2012-11-26 18:00:29 +00:00
@queue = :rpm_worker_observer
def self.perform(options)
bl = BuildList.find options['id']
status = options['status'].to_i
item = find_or_create_item(bl)
2012-12-11 16:56:17 +00:00
2012-12-13 12:30:37 +00:00
fill_container_data(bl, options) if status != STARTED
2012-12-11 16:56:17 +00:00
case status
2012-12-13 12:30:37 +00:00
when COMPLETED
2012-11-26 18:00:29 +00:00
bl.build_success
item.update_attributes({:status => BuildServer::SUCCESS})
2012-12-11 16:56:17 +00:00
bl.now_publish if bl.auto_publish?
2012-12-13 12:30:37 +00:00
when FAILED
2012-11-26 18:00:29 +00:00
bl.build_error
item.update_attributes({:status => BuildServer::BUILD_ERROR})
2012-12-13 12:30:37 +00:00
when STARTED
2012-11-26 18:00:29 +00:00
bl.start_build
2012-12-13 12:30:37 +00:00
when CANCELED
bl.build_canceled
item.update_attributes({:status => BuildList::BUILD_CANCELED})
2012-11-26 18:00:29 +00:00
end
end
class << self
protected
def find_or_create_item(bl)
bl.items.first || bl.items.create({
:version => bl.commit_hash,
:name => bl.project.name,
:status => BuildServer::BUILD_STARTED,
:level => 0
})
end
def fill_container_data(bl, options)
packages = options['packages'] || []
packages.each do |package|
package = bl.packages.build(package)
package.package_type = package['fullname'] =~ /.*\.src\.rpm$/ ? 'source' : 'binary'
package.project_id = bl.project_id
package.platform_id = bl.save_to_platform_id
package.save!
end
update_results(bl, options)
end
2012-11-26 18:00:29 +00:00
end
end
end