rosa-build/lib/abf_worker/publish_observer.rb

64 lines
2.2 KiB
Ruby
Raw Normal View History

module AbfWorker
2012-12-29 10:48:19 +00:00
class PublishObserver < AbfWorker::BaseObserver
@queue = :publish_observer
2013-01-23 09:42:05 +00:00
def self.perform(options)
new(options, BuildList).perform
end
def perform
2013-01-23 09:42:05 +00:00
return if status == STARTED # do nothing when publication started
if options['type'] == 'resign'
AbfWorker::BuildListsPublishTaskManager.unlock_repository options['id']
else
2013-02-12 10:52:40 +00:00
if options['extra']['regenerate'] # Regenerate metadata
AbfWorker::BuildListsPublishTaskManager.unlock_rep_and_platform options['extra']['lock_str']
2013-02-12 10:52:40 +00:00
elsif options['extra']['create_container'] # Container has been created
case status
when COMPLETED
subject.published_container
when FAILED, CANCELED
subject.fail_publish_container
end
update_results
2013-01-25 17:24:46 +00:00
else
update_rpm_builds
2013-01-25 17:24:46 +00:00
end
end
2013-01-23 09:42:05 +00:00
end
protected
def update_rpm_builds
2013-01-23 09:42:05 +00:00
build_lists = BuildList.where(:id => options['build_list_ids'])
build_lists.each do |build_list|
update_results build_list
2013-01-23 09:42:05 +00:00
case status
when COMPLETED
2013-03-22 11:46:22 +00:00
# 'update_column' - when project of build_list has been removed from repository
build_list.published || build_list.update_column(:status, BuildList::BUILD_PUBLISHED)
2013-01-23 09:42:05 +00:00
when FAILED, CANCELED
build_list.fail_publish || build_list.update_column(:status, BuildList::FAILED_PUBLISH)
end
AbfWorker::BuildListsPublishTaskManager.unlock_build_list build_list
end
2013-02-12 11:00:59 +00:00
case status
when COMPLETED
AbfWorker::BuildListsPublishTaskManager.cleanup_completed options['projects_for_cleanup']
when FAILED, CANCELED
AbfWorker::BuildListsPublishTaskManager.cleanup_failed options['projects_for_cleanup']
end
AbfWorker::BuildListsPublishTaskManager.unlock_rep_and_platform options['extra']['lock_str']
2013-01-23 09:42:05 +00:00
end
2013-02-07 12:59:33 +00:00
def update_results(build_list = subject)
results = (build_list.results || []).
2013-02-19 08:44:05 +00:00
select{ |r| r['file_name'] !~ /^abfworker\:\:publish\-(container\-)*worker.*\.log$/ }
results |= options['results']
sort_results_and_save results, build_list
end
end
end