2012-12-10 17:01:34 +00:00
|
|
|
module AbfWorker
|
2012-12-29 10:48:19 +00:00
|
|
|
class PublishObserver < AbfWorker::BaseObserver
|
2016-05-28 19:21:02 +01:00
|
|
|
sidekiq_options :queue => :publish_observer
|
2012-12-10 17:01:34 +00:00
|
|
|
|
2016-05-28 19:21:02 +01:00
|
|
|
def real_perform
|
|
|
|
@subject_class = BuildList
|
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']
|
2014-01-21 04:51:49 +00:00
|
|
|
repository_status = RepositoryStatus.where(id: extra['repository_status_id']).first
|
2013-08-22 22:02:24 +01:00
|
|
|
begin
|
2014-01-21 04:51:49 +00:00
|
|
|
|
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
|
2014-01-21 04:51:49 +00: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
|
2014-01-09 20:54:48 +00:00
|
|
|
bls = extra['build_lists_for_cleanup_from_testing']
|
|
|
|
if status != COMPLETED && bls.present?
|
2014-06-19 20:35:53 +01:00
|
|
|
AbfWorkerService::Base.cleanup_packages_from_testing(
|
2014-01-09 20:54:48 +00:00
|
|
|
repository_status.platform_id,
|
|
|
|
repository_status.repository_id,
|
|
|
|
bls
|
|
|
|
)
|
|
|
|
end
|
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
|
2014-01-21 04:51:49 +00:00
|
|
|
build_lists = BuildList.where(id: options['build_list_ids'])
|
|
|
|
build_lists.each do |build_list|
|
2013-02-05 18:49:26 +00:00
|
|
|
update_results build_list
|
2019-02-16 15:25:41 +00:00
|
|
|
puts "PUBLISH STATUS: #{status}"
|
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
|
2014-06-19 20:35:53 +01:00
|
|
|
AbfWorkerService::Base.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
|
2014-06-19 20:35:53 +01:00
|
|
|
AbfWorkerService::Base.cleanup_completed options['projects_for_cleanup']
|
2013-02-12 11:00:59 +00:00
|
|
|
when FAILED, CANCELED
|
2014-06-19 20:35:53 +01:00
|
|
|
AbfWorkerService::Base.cleanup_failed options['projects_for_cleanup']
|
2013-02-12 11:00:59 +00:00
|
|
|
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
|
2019-02-16 08:26:08 +00:00
|
|
|
end
|