From b46c1e963f73298d5b562d9c4c1d549d958a8458 Mon Sep 17 00:00:00 2001 From: Vokhmin Alexey V Date: Thu, 24 Jan 2013 14:42:03 +0400 Subject: [PATCH 1/3] #848: update StatusInspector, UI --- .../product_build_lists_controller.rb | 1 + .../projects/build_lists_controller.rb | 2 +- .../product_build_lists/_filter.html.haml | 2 ++ .../projects/build_lists/_filter.html.haml | 15 +------- .../build_lists/_server_status.html.haml | 15 ++++++++ config/locales/models/build_list.en.yml | 1 + config/locales/models/build_list.ru.yml | 1 + lib/abf_worker/status_inspector.rb | 36 ++++++++++++++----- 8 files changed, 50 insertions(+), 23 deletions(-) create mode 100644 app/views/projects/build_lists/_server_status.html.haml 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 0da551cb9..2c432ef23 100644 --- a/app/controllers/projects/build_lists_controller.rb +++ b/app/controllers/projects/build_lists_controller.rb @@ -31,7 +31,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 b407f814b..fa5edc6c1 100644 --- a/config/locales/models/build_list.en.yml +++ b/config/locales/models/build_list.en.yml @@ -93,6 +93,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 c18a7a057..b621aec44 100644 --- a/config/locales/models/build_list.ru.yml +++ b/config/locales/models/build_list.ru.yml @@ -90,6 +90,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..7ad4f3d42 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" + 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 } + fill_status status, workers, worker + end + status + end + + def fill_status(status, workers, worker) + redis, key = Resque.redis, "queue:#{worker}_worker" status[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 From 262483f30bf0f6fc4f9daf64a40163e2db3bee06 Mon Sep 17 00:00:00 2001 From: Vokhmin Alexey V Date: Thu, 24 Jan 2013 14:54:57 +0400 Subject: [PATCH 2/3] #848: fix specs --- spec/controllers/projects/build_lists_controller_spec.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/spec/controllers/projects/build_lists_controller_spec.rb b/spec/controllers/projects/build_lists_controller_spec.rb index 1f87374c3..390a22a74 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 From e1b79a3c1f73b6887e8423ba08f10885b5e3a1c7 Mon Sep 17 00:00:00 2001 From: Vokhmin Alexey V Date: Thu, 24 Jan 2013 15:58:42 +0400 Subject: [PATCH 3/3] #848: small refactoring --- lib/abf_worker/status_inspector.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/abf_worker/status_inspector.rb b/lib/abf_worker/status_inspector.rb index 7ad4f3d42..6aa722c01 100644 --- a/lib/abf_worker/status_inspector.rb +++ b/lib/abf_worker/status_inspector.rb @@ -21,14 +21,14 @@ module AbfWorker status = {} queues.each do |worker| workers = Resque.workers.select{ |w| yield w, worker } - fill_status status, workers, worker + status[worker] = status_of_worker workers, worker end status end - def fill_status(status, workers, worker) + def status_of_worker(workers, worker) redis, key = Resque.redis, "queue:#{worker}_worker" - status[worker] = { + { :count => workers.count, :build_tasks => workers.select{ |w| w.working? }.count, :tasks => (redis.llen("#{key}_default") + redis.llen(key))