2012-11-26 18:00:29 +00:00
|
|
|
module AbfWorker
|
2012-12-11 15:25:25 +00:00
|
|
|
class RpmWorkerObserver < AbfWorker::BaseObserver
|
2013-02-05 09:37:18 +00:00
|
|
|
RESTARTED_BUILD_LISTS = 'abf-worker::rpm-worker-observer::restarted-build-lists'
|
2013-02-05 18:49:26 +00:00
|
|
|
|
2014-07-24 20:02:08 +01:00
|
|
|
# EXIT CODES:
|
|
|
|
# 6 - Unpermitted architecture
|
|
|
|
# other - Build error
|
|
|
|
EXIT_CODE_UNPERMITTED_ARCHITECTURE = 6
|
|
|
|
|
2016-05-28 19:21:02 +01:00
|
|
|
sidekiq_options :queue => :rpm_worker_observer
|
|
|
|
|
|
|
|
def real_perform
|
|
|
|
@subject_class = BuildList
|
2019-02-10 14:15:46 +00:00
|
|
|
return if !subject
|
2018-04-09 13:04:16 +01:00
|
|
|
unless subject.valid? && restart_task
|
|
|
|
if options['feedback_from_user']
|
|
|
|
user = User.find options['feedback_from_user']
|
2019-02-10 14:15:46 +00:00
|
|
|
return if !user.system? && subject.builder != user
|
2018-04-09 13:04:16 +01:00
|
|
|
end
|
2016-05-28 19:21:02 +01:00
|
|
|
|
2018-04-09 13:04:16 +01:00
|
|
|
fill_container_data if status != STARTED
|
2016-05-28 19:21:02 +01:00
|
|
|
|
2018-04-09 13:04:16 +01:00
|
|
|
unless subject.valid?
|
2019-03-26 06:39:50 +00:00
|
|
|
subject.update_attribute(:status, BuildList::BUILD_ERROR)
|
2018-04-09 13:04:16 +01:00
|
|
|
return
|
|
|
|
end
|
2016-05-28 19:21:02 +01:00
|
|
|
|
2018-04-09 13:04:16 +01:00
|
|
|
if options['hostname']
|
|
|
|
subject.update_attribute(:hostname, options['hostname'])
|
|
|
|
end
|
2016-05-28 19:21:02 +01:00
|
|
|
|
2018-04-09 13:04:16 +01:00
|
|
|
if options['fail_reason']
|
|
|
|
subject.update_attribute(:fail_reason, options['fail_reason'])
|
|
|
|
end
|
2016-05-28 19:21:02 +01:00
|
|
|
|
2018-04-09 13:04:16 +01:00
|
|
|
if options['commit_hash']
|
|
|
|
subject.update_attribute(:commit_hash, options['commit_hash'])
|
|
|
|
end
|
|
|
|
|
|
|
|
rerunning_tests = subject.rerunning_tests?
|
2016-05-28 19:21:02 +01:00
|
|
|
|
2018-04-09 13:04:16 +01:00
|
|
|
case status
|
|
|
|
when COMPLETED
|
|
|
|
subject.build_success
|
|
|
|
if subject.can_auto_publish? && subject.can_publish?
|
|
|
|
subject.publish
|
|
|
|
elsif subject.auto_publish_into_testing? && subject.can_publish_into_testing?
|
|
|
|
subject.publish_into_testing
|
2016-05-28 19:21:02 +01:00
|
|
|
end
|
2018-04-09 13:04:16 +01:00
|
|
|
when FAILED
|
2016-05-28 19:21:02 +01:00
|
|
|
|
2018-04-09 13:04:16 +01:00
|
|
|
case options['exit_status'].to_i
|
|
|
|
when EXIT_CODE_UNPERMITTED_ARCHITECTURE
|
|
|
|
subject.unpermitted_arch
|
|
|
|
else
|
|
|
|
subject.build_error
|
2016-05-28 19:21:02 +01:00
|
|
|
end
|
2018-04-09 13:04:16 +01:00
|
|
|
|
|
|
|
when STARTED
|
|
|
|
subject.start_build
|
|
|
|
when CANCELED
|
|
|
|
subject.build_canceled
|
|
|
|
when TESTS_FAILED
|
|
|
|
subject.tests_failed
|
|
|
|
end
|
|
|
|
|
|
|
|
if !rerunning_tests && [TESTS_FAILED, COMPLETED].include?(status)
|
|
|
|
subject.publish_container if subject.auto_create_container?
|
2014-07-24 20:02:08 +01:00
|
|
|
end
|
2013-02-19 09:58:34 +00:00
|
|
|
end
|
2013-02-05 18:49:26 +00:00
|
|
|
end
|
2012-12-03 17:17:20 +00:00
|
|
|
|
2013-02-06 10:14:36 +00:00
|
|
|
protected
|
|
|
|
|
2013-02-06 10:54:12 +00:00
|
|
|
def restart_task
|
2013-02-09 21:46:08 +00:00
|
|
|
return false if status != FAILED
|
2014-03-18 21:52:40 +00:00
|
|
|
if Redis.current.lrem(RESTARTED_BUILD_LISTS, 0, subject.id) > 0 || (options['results'] || []).size > 1
|
2013-02-06 10:54:12 +00:00
|
|
|
return false
|
|
|
|
else
|
2014-03-18 21:52:40 +00:00
|
|
|
Redis.current.lpush RESTARTED_BUILD_LISTS, subject.id
|
2013-02-06 10:54:12 +00:00
|
|
|
subject.update_column(:status, BuildList::BUILD_PENDING)
|
2019-03-26 06:39:50 +00:00
|
|
|
subject.update_column(:builder_id, nil)
|
2013-02-06 10:54:12 +00:00
|
|
|
return true
|
2012-12-03 17:17:20 +00:00
|
|
|
end
|
2013-02-06 10:54:12 +00:00
|
|
|
end
|
2012-12-03 17:17:20 +00:00
|
|
|
|
2013-02-05 18:49:26 +00:00
|
|
|
def fill_container_data
|
2013-02-06 14:23:40 +00:00
|
|
|
(options['packages'] || []).each do |package|
|
2013-02-05 18:49:26 +00:00
|
|
|
package = subject.packages.build(package)
|
2014-06-09 21:06:21 +01:00
|
|
|
package.package_type = package['fullname'] =~ /.*\.src\.rpm$/ ? 'source' : 'binary'
|
|
|
|
package.project_id = subject.project_id
|
|
|
|
package.platform_id = subject.save_to_platform_id
|
2013-02-05 18:49:26 +00:00
|
|
|
package.save!
|
2012-11-27 14:22:17 +00:00
|
|
|
end
|
2013-02-05 18:49:26 +00:00
|
|
|
update_results
|
2012-11-26 18:00:29 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|
2019-03-26 06:39:50 +00:00
|
|
|
end
|