#756: update Observers, add TESTS_FAILED status
This commit is contained in:
parent
ae254ee905
commit
67e60f0a1d
|
@ -67,6 +67,7 @@ class BuildList < ActiveRecord::Base
|
|||
FAILED_PUBLISH = 8000
|
||||
REJECTED_PUBLISH = 9000
|
||||
BUILD_CANCELING = 10000
|
||||
TESTS_FAILED = 11000
|
||||
|
||||
STATUSES = [ WAITING_FOR_RESPONSE,
|
||||
BUILD_CANCELED,
|
||||
|
@ -79,7 +80,8 @@ class BuildList < ActiveRecord::Base
|
|||
SUCCESS,
|
||||
BUILD_STARTED,
|
||||
BUILD_ERROR,
|
||||
PROJECT_VERSION_NOT_FOUND
|
||||
PROJECT_VERSION_NOT_FOUND,
|
||||
TESTS_FAILED
|
||||
]
|
||||
|
||||
HUMAN_STATUSES = { WAITING_FOR_RESPONSE => :waiting_for_response,
|
||||
|
@ -94,6 +96,7 @@ class BuildList < ActiveRecord::Base
|
|||
BUILD_STARTED => :build_started,
|
||||
SUCCESS => :success,
|
||||
PROJECT_VERSION_NOT_FOUND => :project_version_not_found,
|
||||
TESTS_FAILED => :tests_failed
|
||||
}
|
||||
|
||||
scope :recent, order("#{table_name}.updated_at DESC")
|
||||
|
@ -204,6 +207,10 @@ class BuildList < ActiveRecord::Base
|
|||
transition [:build_started, :build_canceled, :build_canceling] => :build_error
|
||||
end
|
||||
|
||||
event :tests_failed do
|
||||
transition [:build_started, :build_canceled, :build_canceling] => :tests_failed
|
||||
end
|
||||
|
||||
HUMAN_STATUSES.each do |code,name|
|
||||
state name, :value => code
|
||||
end
|
||||
|
|
|
@ -114,6 +114,7 @@ en:
|
|||
build_lists: All
|
||||
build_error: Build error
|
||||
build_published: Build has been published
|
||||
tests_failed: Tests failed
|
||||
rejected_publish: Publishing rejected
|
||||
build_publish: Build is being published
|
||||
failed_publish: Publishing error
|
||||
|
|
|
@ -113,6 +113,7 @@ ru:
|
|||
build_lists: Всего
|
||||
build_error: ошибка сборки
|
||||
build_published: опубликован
|
||||
tests_failed: тесты не прошли
|
||||
rejected_publish: публикация отклонена
|
||||
build_publish: публикуется
|
||||
failed_publish: ошибка публикации
|
||||
|
|
|
@ -6,14 +6,33 @@ module AbfWorker
|
|||
STARTED = 3
|
||||
CANCELED = 4
|
||||
|
||||
def self.update_results(subject, options)
|
||||
results = (subject.results || []) + options['results']
|
||||
sort_results_and_save(subject, results)
|
||||
attr_accessor :status, :options
|
||||
|
||||
protected
|
||||
|
||||
def initialize(options, subject_class)
|
||||
@status = options['status'].to_i
|
||||
@options = options
|
||||
@subject_class = subject_class
|
||||
end
|
||||
|
||||
def self.sort_results_and_save(subject, results)
|
||||
subject.results = results.sort_by{ |r| r['file_name'] }
|
||||
subject.save!
|
||||
def subject
|
||||
@subject ||= @subject_class.find options['id']
|
||||
end
|
||||
|
||||
def perform
|
||||
raise NotImplementedError, "You should implement this method"
|
||||
end
|
||||
|
||||
def update_results
|
||||
results = (subject.results || []) + options['results']
|
||||
sort_results_and_save results
|
||||
end
|
||||
|
||||
def sort_results_and_save(results, item = nil)
|
||||
item ||= subject
|
||||
item.results = results.sort_by{ |r| r['file_name'] }
|
||||
item.save!
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -3,21 +3,23 @@ module AbfWorker
|
|||
@queue = :iso_worker_observer
|
||||
|
||||
def self.perform(options)
|
||||
status = options['status'].to_i
|
||||
pbl = ProductBuildList.find options['id']
|
||||
new(options, ProductBuildList).perform
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
def perform
|
||||
case status
|
||||
when COMPLETED
|
||||
pbl.build_success
|
||||
subject.build_success
|
||||
when FAILED
|
||||
pbl.build_error
|
||||
subject.build_error
|
||||
when STARTED
|
||||
pbl.start_build
|
||||
subject.start_build
|
||||
when CANCELED
|
||||
pbl.build_canceled
|
||||
end
|
||||
if status != STARTED
|
||||
update_results(pbl, options)
|
||||
subject.build_canceled
|
||||
end
|
||||
update_results if status != STARTED
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -4,53 +4,53 @@ module AbfWorker
|
|||
|
||||
|
||||
def self.perform(options)
|
||||
status = options['status'].to_i
|
||||
new(options, BuildList).perform
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
def perform
|
||||
return if status == STARTED # do nothing when publication started
|
||||
if options['type'] == 'resign'
|
||||
AbfWorker::BuildListsPublishTaskManager.unlock_repository options['id']
|
||||
else
|
||||
if options['extra']['create_container'] # Container has been created
|
||||
bl = BuildList.find(options['id'])
|
||||
case status
|
||||
when COMPLETED
|
||||
bl.published_container
|
||||
subject.published_container
|
||||
when FAILED, CANCELED
|
||||
bl.fail_publish_container
|
||||
subject.fail_publish_container
|
||||
end
|
||||
update_results(bl, options)
|
||||
update_results
|
||||
else
|
||||
update_rpm_builds options, status
|
||||
update_rpm_builds
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def self.update_rpm_builds(options, status)
|
||||
def update_rpm_builds
|
||||
build_lists = BuildList.where(:id => options['build_list_ids'])
|
||||
build_lists.each do |bl|
|
||||
update_results(bl, options)
|
||||
build_lists.each do |build_list|
|
||||
update_results build_list
|
||||
case status
|
||||
when COMPLETED
|
||||
bl.published
|
||||
build_list.published
|
||||
AbfWorker::BuildListsPublishTaskManager.cleanup_completed options['projects_for_cleanup']
|
||||
when FAILED, CANCELED
|
||||
bl.fail_publish
|
||||
build_list.fail_publish
|
||||
AbfWorker::BuildListsPublishTaskManager.cleanup_failed options['projects_for_cleanup']
|
||||
end
|
||||
AbfWorker::BuildListsPublishTaskManager.unlock_build_list bl
|
||||
AbfWorker::BuildListsPublishTaskManager.unlock_build_list build_list
|
||||
end
|
||||
bl = build_lists.first || BuildList.find(options['id'])
|
||||
AbfWorker::BuildListsPublishTaskManager.unlock_rep_and_platform bl
|
||||
build_list = build_lists.first || BuildList.find(options['id'])
|
||||
AbfWorker::BuildListsPublishTaskManager.unlock_rep_and_platform build_list
|
||||
end
|
||||
|
||||
class << self
|
||||
protected
|
||||
|
||||
def update_results(subject, options)
|
||||
results = (subject.results || []).
|
||||
select{ |r| r['file_name'] !~ /^abfworker\:\:publish\-worker.*\.log$/ }
|
||||
results |= options['results']
|
||||
sort_results_and_save(subject, results)
|
||||
end
|
||||
def update_results(build_list)
|
||||
results = (build_list.results || []).
|
||||
select{ |r| r['file_name'] !~ /^abfworker\:\:publish\-worker.*\.log$/ }
|
||||
results |= options['results']
|
||||
sort_results_and_save results, build_list
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,53 +1,58 @@
|
|||
module AbfWorker
|
||||
class RpmWorkerObserver < AbfWorker::BaseObserver
|
||||
TESTS_FAILED = 5
|
||||
|
||||
@queue = :rpm_worker_observer
|
||||
|
||||
def self.perform(options)
|
||||
bl = BuildList.find options['id']
|
||||
status = options['status'].to_i
|
||||
item = find_or_create_item(bl)
|
||||
new(options, BuildList).perform
|
||||
end
|
||||
|
||||
fill_container_data(bl, options) if status != STARTED
|
||||
protected
|
||||
|
||||
def perform
|
||||
item = find_or_create_item
|
||||
|
||||
fill_container_data if status != STARTED
|
||||
|
||||
case status
|
||||
when COMPLETED
|
||||
bl.build_success
|
||||
item.update_attributes({:status => BuildList::SUCCESS})
|
||||
bl.now_publish if bl.auto_publish?
|
||||
subject.build_success
|
||||
subject.now_publish if subject.auto_publish?
|
||||
when FAILED
|
||||
bl.build_error
|
||||
subject.build_error
|
||||
item.update_attributes({:status => BuildList::BUILD_ERROR})
|
||||
when STARTED
|
||||
bl.start_build
|
||||
subject.start_build
|
||||
when CANCELED
|
||||
bl.build_canceled
|
||||
subject.build_canceled
|
||||
item.update_attributes({:status => BuildList::BUILD_CANCELED})
|
||||
when TESTS_FAILED
|
||||
subject.tests_failed
|
||||
end
|
||||
|
||||
item.update_attributes({:status => BuildList::SUCCESS}) if [TESTS_FAILED, COMPLETED].include?(status)
|
||||
end
|
||||
|
||||
class << self
|
||||
protected
|
||||
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
|
||||
|
||||
def find_or_create_item(bl)
|
||||
bl.items.first || bl.items.create({
|
||||
:version => bl.commit_hash,
|
||||
:name => bl.project.name,
|
||||
:status => BuildList::BUILD_STARTED,
|
||||
:level => 0
|
||||
})
|
||||
end
|
||||
|
||||
def fill_container_data(bl, options)
|
||||
packages = options['packages'] || []
|
||||
packages.each do |package|
|
||||
package = bl.packages.build(package)
|
||||
package.package_type = package['fullname'] =~ /.*\.src\.rpm$/ ? 'source' : 'binary'
|
||||
package.project_id = bl.project_id
|
||||
package.platform_id = bl.save_to_platform_id
|
||||
package.save!
|
||||
end
|
||||
update_results(bl, options)
|
||||
def fill_container_data
|
||||
packages = options['packages'] || []
|
||||
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
|
||||
end
|
||||
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue