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