rosa-build/lib/abf_worker/publish_observer.rb

94 lines
3.6 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
extra = options['extra']
2013-08-26 17:56:46 +01:00
repository_status = RepositoryStatus.where(:id => extra['repository_status_id']).first
begin
2013-08-27 16:43:30 +01:00
if extra['regenerate'] || extra['regenerate_platform']
log_sha1 = (options['results'].try(:first) || {}).fetch('sha1', nil)
end
if extra['regenerate'] # Regenerate metadata
repository_status.last_regenerated_at = Time.now.utc
repository_status.last_regenerated_status = status
2013-08-27 16:43:30 +01:00
repository_status.last_regenerated_log_sha1 = log_sha1
elsif extra['regenerate_platform'] # Regenerate metadata for Software Center
2013-08-26 18:13:03 +01:00
if platform = Platform.where(:id => extra['platform_id']).first
platform.last_regenerated_at = Time.now.utc
platform.last_regenerated_status = status
2013-08-27 16:43:30 +01:00
platform.last_regenerated_log_sha1 = log_sha1
platform.ready
end
elsif extra['create_container'] # Container has been created
case status
when COMPLETED
subject.published_container
when FAILED, CANCELED
subject.fail_publish_container
end
update_results
elsif !extra['resign'] # Simple publish
bls = extra['build_lists_for_cleanup_from_testing']
if status != COMPLETED && bls.present?
AbfWorker::BuildListsPublishTaskManager.cleanup_packages_from_testing(
repository_status.platform_id,
repository_status.repository_id,
bls
)
end
update_rpm_builds
2013-01-25 17:24:46 +00:00
end
ensure
repository_status.ready if repository_status.present?
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-11-05 18:33:28 +00:00
if build_list.build_publish?
# 'update_column' - when project of build_list has been removed from repository
build_list.published || build_list.update_column(:status, BuildList::BUILD_PUBLISHED)
elsif build_list.build_publish_into_testing?
build_list.published_into_testing || build_list.update_column(:status, BuildList::BUILD_PUBLISHED_INTO_TESTING)
end
2013-01-23 09:42:05 +00:00
when FAILED, CANCELED
2013-11-05 18:33:28 +00:00
if build_list.build_publish?
build_list.fail_publish || build_list.update_column(:status, BuildList::FAILED_PUBLISH)
elsif build_list.build_publish_into_testing?
build_list.fail_publish_into_testing || build_list.update_column(:status, BuildList::FAILED_PUBLISH_INTO_TESTING)
end
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
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