Merge pull request #850 from warpc/848-add-status-information-for-product-build-lists

[refs #848]: add status information about servers for ProductBuildLists
This commit is contained in:
Vladimir Sharshov 2013-01-25 03:37:41 -08:00
commit bf445d9e5e
9 changed files with 52 additions and 24 deletions

View File

@ -80,6 +80,7 @@ class Platforms::ProductBuildListsController < Platforms::BaseController
@product_build_lists = @product_build_lists.for_status(params[:status]) if params[:status].present?
end
@product_build_lists = @product_build_lists.recent.paginate :page => params[:page]
@build_server_status = AbfWorker::StatusInspector.products_status
end
protected

View File

@ -28,7 +28,7 @@ class Projects::BuildListsController < Projects::BaseController
@build_lists = BuildList.where(:id => @bls.pluck("#{BuildList.table_name}.id")).recent
@build_lists = @build_lists.includes [:save_to_platform, :save_to_repository, :arch, :user, :project => [:owner]]
@build_server_status = AbfWorker::StatusInspector.get_status
@build_server_status = AbfWorker::StatusInspector.projects_status
end
def new

View File

@ -1,4 +1,6 @@
- content_for :sidebar do
= render 'projects/build_lists/server_status', :queues => [:iso]
= form_tag product_build_lists_path, :method => :get, :html => {:class => :form} do
.block
%h3.small= t("activerecord.attributes.product_build_list.status")

View File

@ -1,18 +1,5 @@
- content_for :sidebar do
.bordered.nopadding
%h3= t('layout.build_lists.build_server_status.header')
- [:rpm, :publish].each do |queue|
.table
.lefter= t("layout.build_lists.build_server_status.#{queue}_workers")
.both
- [:count, :tasks, :build_tasks].each do |metric|
.table
.lefter= t("layout.build_lists.build_server_status.#{metric}")
.righter= @build_server_status[queue][metric]
.both
%br
= link_to t('layout.build_lists.new_header'), new_project_build_list_path(@project), :class => 'button' if @project and can?(:create, @project.build_lists.build)
= render 'server_status'
= form_for :filter, :url => @action_url, :html => { :method => :post, :class => :form } do |f|
- if current_user

View File

@ -0,0 +1,15 @@
- queues ||= [:rpm, :publish]
.bordered.nopadding
%h3= t('layout.build_lists.build_server_status.header')
- queues.each do |queue|
.table
.lefter= t("layout.build_lists.build_server_status.#{queue}_workers")
.both
- [:count, :tasks, :build_tasks].each do |metric|
.table
.lefter= t("layout.build_lists.build_server_status.#{metric}")
.righter= @build_server_status[queue][metric]
.both
%br
= link_to t('layout.build_lists.new_header'), new_project_build_list_path(@project), :class => 'button' if @project and can?(:create, @project.build_lists.build)

View File

@ -94,6 +94,7 @@ en:
tasks: '- tasks in queue'
build_tasks: '- tasks in execution'
rpm_workers: Workers for building
iso_workers: Workers for building
publish_workers: Workers for publishing
items:

View File

@ -91,6 +91,7 @@ ru:
tasks: '- заданий в очереди'
build_tasks: '- заданий выполняется'
rpm_workers: Воркеров для сборки
iso_workers: Воркеров для сборки
publish_workers: Воркеров для публикации
items:

View File

@ -1,20 +1,40 @@
module AbfWorker
class StatusInspector
def self.get_status
redis, all_workers = Resque.redis, Resque.workers
class << self
def projects_status
get_status(:rpm, :publish) { |w, worker|
w.to_s =~ /#{worker}_worker_default/
}
end
def products_status
get_status(:iso) { |w, worker|
str = w.to_s
str =~ /iso_worker/ && str !~ /observer/
}
end
protected
def get_status(*queues)
status = {}
[:rpm, :publish].each do |worker|
workers = all_workers.select{ |w| w.to_s =~ /#{worker}_worker_default/ }
key = "queue:#{worker}_worker"
status[worker] = {
queues.each do |worker|
workers = Resque.workers.select{ |w| yield w, worker }
status[worker] = status_of_worker workers, worker
end
status
end
def status_of_worker(workers, worker)
redis, key = Resque.redis, "queue:#{worker}_worker"
{
:count => workers.count,
:build_tasks => workers.select{ |w| w.working? }.count,
:tasks => (redis.llen("#{key}_default") + redis.llen(key))
}
end
status
end
end
end
end

View File

@ -94,6 +94,7 @@ describe Projects::BuildListsController do
:build_for_platforms => [@platform.id]
}
any_instance_of(Project, :versions => ['v1.0', 'v2.0'])
stub_redis
end
context 'for guest' do