rosa-build/lib/abf_worker/rpm_worker_observer.rb

83 lines
2.4 KiB
Ruby
Raw Normal View History

2012-11-26 18:00:29 +00:00
module AbfWorker
2012-12-11 15:25:25 +00:00
class RpmWorkerObserver < AbfWorker::BaseObserver
RESTARTED_BUILD_LISTS = 'abf-worker::rpm-worker-observer::restarted-build-lists'
2012-11-26 18:00:29 +00:00
@queue = :rpm_worker_observer
def self.perform(options)
new(options, BuildList).perform
end
def perform
2013-02-06 10:54:12 +00:00
return if restart_task
2013-10-17 19:22:40 +01:00
if options['feedback_from_user']
user = User.find options['feedback_from_user']
return if !user.system? && subject.builder != user
end
2012-12-11 16:56:17 +00:00
2013-02-06 10:54:12 +00:00
item = find_or_create_item
fill_container_data if status != STARTED
2012-12-11 16:56:17 +00:00
case status
2012-12-13 12:30:37 +00:00
when COMPLETED
subject.build_success
if subject.can_auto_publish?
subject.now_publish
elsif subject.auto_publish_into_testing?
subject.now_publish_into_testing
end
2012-12-13 12:30:37 +00:00
when FAILED
subject.build_error
2014-01-21 04:51:49 +00:00
item.update_attributes({status: BuildList::BUILD_ERROR})
2012-12-13 12:30:37 +00:00
when STARTED
subject.start_build
2012-12-13 12:30:37 +00:00
when CANCELED
subject.build_canceled
2014-01-21 04:51:49 +00:00
item.update_attributes({status: BuildList::BUILD_CANCELED})
when TESTS_FAILED
subject.tests_failed
2012-11-26 18:00:29 +00:00
end
if [TESTS_FAILED, COMPLETED].include?(status)
2014-01-21 04:51:49 +00:00
item.update_attributes({status: BuildList::SUCCESS})
subject.publish_container if subject.auto_create_container?
end
end
protected
def find_or_create_item
subject.items.first || subject.items.create({
2014-01-21 04:51:49 +00:00
version: subject.commit_hash,
name: subject.project.name,
status: BuildList::BUILD_STARTED,
level: 0
})
end
2013-02-06 10:54:12 +00:00
def restart_task
return false if status != FAILED
2013-02-06 10:54:12 +00:00
redis = Resque.redis
if redis.lrem(RESTARTED_BUILD_LISTS, 0, subject.id) > 0 || (options['results'] || []).size > 1
2013-02-06 10:54:12 +00:00
return false
else
redis.lpush RESTARTED_BUILD_LISTS, subject.id
subject.update_column(:status, BuildList::BUILD_PENDING)
2013-11-29 12:58:37 +00:00
subject.restart_job if subject.external_nodes.blank?
2013-02-06 10:54:12 +00:00
return true
end
2013-02-06 10:54:12 +00:00
end
def fill_container_data
2013-02-06 14:23:40 +00:00
(options['packages'] || []).each do |package|
package = subject.packages.build(package)
package.package_type = package['fullname'] =~ /.*\.src\.rpm$/ ? 'source' : 'binary'
package.project_id = subject.project_id
package.platform_id = subject.save_to_platform_id
package.save!
end
update_results
2012-11-26 18:00:29 +00:00
end
end
end