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
|
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
|
2013-02-22 10:20:47 +00:00
|
|
|
subject.now_publish if subject.auto_publish? && subject.can_publish?
|
2012-12-13 12:30:37 +00:00
|
|
|
when FAILED
|
2013-02-05 18:49:26 +00:00
|
|
|
subject.build_error
|
2013-01-24 11:32:00 +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
|
2012-12-06 16:28:44 +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)
|
|
|
|
item.update_attributes({:status => BuildList::SUCCESS})
|
|
|
|
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({
|
|
|
|
:version => subject.commit_hash,
|
|
|
|
:name => subject.project.name,
|
|
|
|
:status => BuildList::BUILD_STARTED,
|
|
|
|
:level => 0
|
|
|
|
})
|
|
|
|
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)
|
|
|
|
subject.add_job_to_abf_worker_queue
|
|
|
|
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
|