diff --git a/app/controllers/platforms/product_build_lists_controller.rb b/app/controllers/platforms/product_build_lists_controller.rb index e5b6b6c45..ae0083893 100644 --- a/app/controllers/platforms/product_build_lists_controller.rb +++ b/app/controllers/platforms/product_build_lists_controller.rb @@ -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 diff --git a/app/controllers/projects/build_lists_controller.rb b/app/controllers/projects/build_lists_controller.rb index d10efc2b5..5d2e207c5 100644 --- a/app/controllers/projects/build_lists_controller.rb +++ b/app/controllers/projects/build_lists_controller.rb @@ -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 diff --git a/app/views/platforms/product_build_lists/_filter.html.haml b/app/views/platforms/product_build_lists/_filter.html.haml index 8a9e88f02..fa2824e48 100644 --- a/app/views/platforms/product_build_lists/_filter.html.haml +++ b/app/views/platforms/product_build_lists/_filter.html.haml @@ -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") diff --git a/app/views/projects/build_lists/_filter.html.haml b/app/views/projects/build_lists/_filter.html.haml index 6656511e0..d3bf13aea 100644 --- a/app/views/projects/build_lists/_filter.html.haml +++ b/app/views/projects/build_lists/_filter.html.haml @@ -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 diff --git a/app/views/projects/build_lists/_server_status.html.haml b/app/views/projects/build_lists/_server_status.html.haml new file mode 100644 index 000000000..7bef79c07 --- /dev/null +++ b/app/views/projects/build_lists/_server_status.html.haml @@ -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) \ No newline at end of file diff --git a/config/locales/models/build_list.en.yml b/config/locales/models/build_list.en.yml index f251ad4df..eb8176233 100644 --- a/config/locales/models/build_list.en.yml +++ b/config/locales/models/build_list.en.yml @@ -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: diff --git a/config/locales/models/build_list.ru.yml b/config/locales/models/build_list.ru.yml index 6bb557802..878b108c0 100644 --- a/config/locales/models/build_list.ru.yml +++ b/config/locales/models/build_list.ru.yml @@ -91,6 +91,7 @@ ru: tasks: '- заданий в очереди' build_tasks: '- заданий выполняется' rpm_workers: Воркеров для сборки + iso_workers: Воркеров для сборки publish_workers: Воркеров для публикации items: diff --git a/lib/abf_worker/status_inspector.rb b/lib/abf_worker/status_inspector.rb index cf0f50921..6aa722c01 100644 --- a/lib/abf_worker/status_inspector.rb +++ b/lib/abf_worker/status_inspector.rb @@ -1,20 +1,40 @@ module AbfWorker class StatusInspector - def self.get_status - redis, all_workers = Resque.redis, Resque.workers - status = {} - [:rpm, :publish].each do |worker| - workers = all_workers.select{ |w| w.to_s =~ /#{worker}_worker_default/ } - key = "queue:#{worker}_worker" - status[worker] = { + 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 = {} + 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 \ No newline at end of file diff --git a/spec/controllers/projects/build_lists_controller_spec.rb b/spec/controllers/projects/build_lists_controller_spec.rb index 557d49af9..dd4605566 100644 --- a/spec/controllers/projects/build_lists_controller_spec.rb +++ b/spec/controllers/projects/build_lists_controller_spec.rb @@ -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