2012-12-10 17:01:34 +00:00
|
|
|
module AbfWorker
|
2012-12-29 10:48:19 +00:00
|
|
|
class PublishObserver < AbfWorker::BaseObserver
|
|
|
|
@queue = :publish_observer
|
2012-12-10 17:01:34 +00:00
|
|
|
|
2013-01-17 14:15:03 +00:00
|
|
|
|
2013-01-23 09:42:05 +00:00
|
|
|
def self.perform(options)
|
2013-02-05 18:49:26 +00:00
|
|
|
new(options, BuildList).perform
|
|
|
|
end
|
|
|
|
|
|
|
|
def perform
|
2013-01-23 09:42:05 +00:00
|
|
|
return if status == STARTED # do nothing when publication started
|
2013-08-26 17:25:41 +01:00
|
|
|
extra = options['extra']
|
2013-08-26 17:56:46 +01:00
|
|
|
repository_status = RepositoryStatus.where(:id => extra['repository_status_id']).first
|
2013-08-22 22:02:24 +01:00
|
|
|
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
|
|
|
|
|
2013-08-26 17:25:41 +01:00
|
|
|
if extra['regenerate'] # Regenerate metadata
|
2013-08-25 17:30:23 +01:00
|
|
|
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
|
2013-08-26 17:25:41 +01:00
|
|
|
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
|
2013-08-23 15:24:01 +01:00
|
|
|
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
|
2013-08-23 15:24:01 +01:00
|
|
|
platform.ready
|
|
|
|
end
|
2013-08-26 17:25:41 +01:00
|
|
|
elsif extra['create_container'] # Container has been created
|
2013-01-28 14:44:06 +00:00
|
|
|
case status
|
|
|
|
when COMPLETED
|
2013-02-05 18:49:26 +00:00
|
|
|
subject.published_container
|
2013-01-28 14:44:06 +00:00
|
|
|
when FAILED, CANCELED
|
2013-02-05 18:49:26 +00:00
|
|
|
subject.fail_publish_container
|
2013-01-28 14:44:06 +00:00
|
|
|
end
|
2013-02-05 18:49:26 +00:00
|
|
|
update_results
|
2013-08-26 17:25:41 +01:00
|
|
|
elsif !extra['resign'] # Simple publish
|
2013-02-05 18:49:26 +00:00
|
|
|
update_rpm_builds
|
2013-01-25 17:24:46 +00:00
|
|
|
end
|
2013-08-22 22:02:24 +01:00
|
|
|
ensure
|
2013-08-25 17:30:23 +01:00
|
|
|
repository_status.ready if repository_status.present?
|
2012-12-11 10:42:15 +00:00
|
|
|
end
|
2013-01-23 09:42:05 +00:00
|
|
|
end
|
2012-12-11 10:42:15 +00:00
|
|
|
|
2013-02-06 10:14:36 +00:00
|
|
|
protected
|
|
|
|
|
2013-02-05 18:49:26 +00:00
|
|
|
def update_rpm_builds
|
2013-01-23 09:42:05 +00:00
|
|
|
build_lists = BuildList.where(:id => options['build_list_ids'])
|
2013-02-05 18:49:26 +00:00
|
|
|
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
|
2013-01-17 14:15:03 +00:00
|
|
|
end
|
2013-02-05 18:49:26 +00:00
|
|
|
AbfWorker::BuildListsPublishTaskManager.unlock_build_list build_list
|
2013-01-17 14:15:03 +00:00
|
|
|
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)
|
2013-02-05 18:49:26 +00:00
|
|
|
results = (build_list.results || []).
|
2013-02-19 08:44:05 +00:00
|
|
|
select{ |r| r['file_name'] !~ /^abfworker\:\:publish\-(container\-)*worker.*\.log$/ }
|
2013-02-05 18:49:26 +00:00
|
|
|
results |= options['results']
|
|
|
|
sort_results_and_save results, build_list
|
2012-12-12 12:32:47 +00:00
|
|
|
end
|
2012-12-10 17:01:34 +00:00
|
|
|
end
|
|
|
|
end
|