2012-11-26 18:00:29 +00:00
|
|
|
module AbfWorker
|
|
|
|
class RpmWorkerObserver
|
2012-12-06 15:22:27 +00:00
|
|
|
BUILD_COMPLETED = 0
|
|
|
|
BUILD_FAILED = 1
|
|
|
|
BUILD_PENDING = 2
|
|
|
|
BUILD_STARTED = 3
|
|
|
|
BUILD_CANCELED = 4
|
|
|
|
|
2012-11-26 18:00:29 +00:00
|
|
|
@queue = :rpm_worker_observer
|
|
|
|
|
|
|
|
def self.perform(options)
|
|
|
|
bl = BuildList.find options['id']
|
2012-11-27 14:22:17 +00:00
|
|
|
status = options['status'].to_i
|
2012-12-03 17:17:20 +00:00
|
|
|
item = find_or_create_item(bl)
|
2012-11-27 14:22:17 +00:00
|
|
|
case status
|
2012-12-06 15:22:27 +00:00
|
|
|
when BUILD_COMPLETED
|
2012-11-26 18:00:29 +00:00
|
|
|
bl.build_success
|
2012-12-03 17:17:20 +00:00
|
|
|
item.update_attributes({:status => BuildServer::SUCCESS})
|
2012-12-06 15:22:27 +00:00
|
|
|
when BUILD_FAILED
|
2012-11-26 18:00:29 +00:00
|
|
|
bl.build_error
|
2012-12-03 17:17:20 +00:00
|
|
|
item.update_attributes({:status => BuildServer::BUILD_ERROR})
|
2012-12-06 15:22:27 +00:00
|
|
|
when BUILD_STARTED
|
2012-11-27 14:22:17 +00:00
|
|
|
bl.bs_id = bl.id
|
2012-12-03 17:17:20 +00:00
|
|
|
bl.save!
|
2012-11-26 18:00:29 +00:00
|
|
|
bl.start_build
|
2012-12-06 15:22:27 +00:00
|
|
|
when BUILD_CANCELED
|
|
|
|
bl.update_attributes({:status => BuildList::BUILD_CANCELED})
|
2012-12-06 16:28:44 +00:00
|
|
|
item.update_attributes({:status => BuildList::BUILD_CANCELED})
|
2012-11-26 18:00:29 +00:00
|
|
|
end
|
2012-12-06 15:22:27 +00:00
|
|
|
if status != BUILD_STARTED
|
2012-12-03 17:17:20 +00:00
|
|
|
fill_container_data bl, options
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
class << self
|
|
|
|
protected
|
|
|
|
|
|
|
|
def find_or_create_item(bl)
|
|
|
|
bl.items.first || bl.items.create({
|
2012-12-04 15:48:30 +00:00
|
|
|
:version => bl.commit_hash,
|
2012-12-03 17:17:20 +00:00
|
|
|
: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
|
|
|
|
|
|
|
|
container = (options['results'] || []).
|
|
|
|
select{ |r| r['file_name'] !~ /.*\.log$/ }.first
|
|
|
|
sha1 = container ? container['sha1'] : nil
|
2012-11-27 14:22:17 +00:00
|
|
|
bl.results = options['results']
|
2012-12-03 17:17:20 +00:00
|
|
|
bl.container_path = "http://file-store.rosalinux.ru/api/v1/file_stores/#{sha1}" if sha1
|
|
|
|
bl.save!
|
2012-11-27 14:22:17 +00:00
|
|
|
end
|
2012-11-26 18:00:29 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|
2012-12-06 16:00:24 +00:00
|
|
|
end
|