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
|
|
|
|
2012-11-26 18:00:29 +00:00
|
|
|
@queue = :rpm_worker_observer
|
|
|
|
|
|
|
|
def self.perform(options)
|
2013-02-05 18:49:26 +00:00
|
|
|
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
|
2013-02-05 18:49:26 +00:00
|
|
|
fill_container_data if status != STARTED
|
2012-12-11 16:56:17 +00:00
|
|
|
|
2012-11-27 14:22:17 +00:00
|
|
|
case status
|
2012-12-13 12:30:37 +00:00
|
|
|
when COMPLETED
|
2013-02-05 18:49:26 +00:00
|
|
|
subject.build_success
|
2014-02-19 21:19:49 +00:00
|
|
|
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
|
2013-02-05 18:49:26 +00:00
|
|
|
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
|
2013-02-05 18:49:26 +00:00
|
|
|
subject.start_build
|
2012-12-13 12:30:37 +00:00
|
|
|
when CANCELED
|
2013-02-05 18:49:26 +00:00
|
|
|
subject.build_canceled
|
2014-01-21 04:51:49 +00:00
|
|
|
item.update_attributes({status: BuildList::BUILD_CANCELED})
|
2013-02-05 18:49:26 +00:00
|
|
|
when TESTS_FAILED
|
|
|
|
subject.tests_failed
|
2012-11-26 18:00:29 +00:00
|
|
|
end
|
2012-12-03 17:17:20 +00:00
|
|
|
|
2013-02-19 09:58:34 +00:00
|
|
|
if [TESTS_FAILED, COMPLETED].include?(status)
|
2014-01-21 04:51:49 +00:00
|
|
|
item.update_attributes({status: BuildList::SUCCESS})
|
2013-02-19 09:58:34 +00:00
|
|
|
subject.publish_container if subject.auto_create_container?
|
|
|
|
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-05 18:49:26 +00:00
|
|
|
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
|
2013-02-05 18:49:26 +00:00
|
|
|
})
|
|
|
|
end
|
2012-12-03 17:17:20 +00:00
|
|
|
|
2013-02-06 10:54:12 +00:00
|
|
|
def restart_task
|
2013-02-09 21:46:08 +00:00
|
|
|
return false if status != FAILED
|
2013-02-06 10:54:12 +00:00
|
|
|
redis = Resque.redis
|
2013-02-09 21:46:08 +00:00
|
|
|
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
|
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)
|
|
|
|
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!
|
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
|
|
|
|
end
|