#823: update PublishObserver

This commit is contained in:
Vokhmin Alexey V 2013-01-12 21:18:13 +04:00
parent 19b7caef02
commit 73b769aeb5
2 changed files with 30 additions and 15 deletions

View File

@ -33,6 +33,15 @@ module AbfWorker
end end
end end
def self.unlock_build_list(build_list)
Resque.redis.lrem(LOCKED_BUILD_LISTS, 0, build_list.id)
end
def self.unlock_rep_and_platform(build_list)
key = "#{build_list.save_to_repository_id}-#{build_list.build_for_platform_id}"
Resque.redis.lrem(LOCKED_REP_AND_PLATFORMS, 0, key)
end
private private
def create_task(save_to_repository_id, build_for_platform_id) def create_task(save_to_repository_id, build_for_platform_id)
@ -71,20 +80,25 @@ module AbfWorker
packages = {:sources => [], :binaries => {:x86_64 => [], :i586 => []}} packages = {:sources => [], :binaries => {:x86_64 => [], :i586 => []}}
old_packages = packages.clone old_packages = packages.clone
build_list_ids = []
build_lists.each do |bl| build_lists.each do |bl|
fill_packages(bl, packages) fill_packages(bl, packages)
bl.last_published.includes(:packages).limit(5).each{ |old_bl| bl.last_published.includes(:packages).limit(5).each{ |old_bl|
fill_packages(old_bl, old_packages) fill_packages(old_bl, old_packages)
} }
build_list_ids << bl.id
@redis.lpush(LOCKED_BUILD_LISTS, bl.id) @redis.lpush(LOCKED_BUILD_LISTS, bl.id)
end end
options.merge!({:packages => packages, :old_packages => old_packages})
Resque.push( Resque.push(
worker_queue, worker_queue,
'class' => worker_class, 'class' => worker_class,
'args' => [options] 'args' => [options.merge({
:packages => packages,
:old_packages => old_packages,
:build_list_ids => build_list_ids
})]
) )
return true return true
end end

View File

@ -3,26 +3,27 @@ module AbfWorker
@queue = :publish_observer @queue = :publish_observer
def self.perform(options) def self.perform(options)
bl = BuildList.find options['id'] build_lists = BuildList.where(:id => options['build_list_ids'])
status = options['status'].to_i status = options['status'].to_i
case status build_lists.each do |bl|
when COMPLETED
bl.published
update_results(bl, options)
when FAILED
bl.fail_publish
update_results(bl, options)
when CANCELED
bl.fail_publish
update_results(bl, options) update_results(bl, options)
case status
when COMPLETED
bl.published
when FAILED
bl.fail_publish
when CANCELED
bl.fail_publish
end
AbfWorker::BuildListsPublishTaskManager.unlock_build_list bl
end end
AbfWorker::BuildListsPublishTaskManager.unlock_rep_and_platform build_lists.first
end end
def self.update_results(subject, options) def self.update_results(subject, options)
results = (subject.results || []). results = (subject.results || []).
map{ |r| r if r['file_name'] !~ /^abfworker\:\:publish\-worker.*\.log$/ }. select{ |r| r['file_name'] !~ /^abfworker\:\:publish\-worker.*\.log$/ }
compact results |= options['results']
results += options['results']
sort_results_and_save(subject, results) sort_results_and_save(subject, results)
end end