From 8cbe33ab0a28824e728635c521eb4d933990a4ca Mon Sep 17 00:00:00 2001 From: Wedge Date: Wed, 15 Jun 2016 03:17:42 +0300 Subject: [PATCH] Readd status panel --- .../build_lists/build_lists_controller.js.erb | 2 +- .../statistics_controller.js.coffee | 2 +- .../angularjs/models/build_list.js.erb | 1 - .../services/build_lists_service.js.erb | 3 +- .../projects/build_lists_controller.rb | 2 +- .../projects/projects_controller.rb | 2 +- app/presenters/abf_worker_status_presenter.rb | 53 ++++--------------- .../build_lists/_server_status.html.slim | 52 +++++++----------- .../projects/build_lists/index.html.slim | 1 + 9 files changed, 36 insertions(+), 82 deletions(-) diff --git a/app/assets/javascripts/angularjs/build_lists/build_lists_controller.js.erb b/app/assets/javascripts/angularjs/build_lists/build_lists_controller.js.erb index 1774fd560..d2476f894 100644 --- a/app/assets/javascripts/angularjs/build_lists/build_lists_controller.js.erb +++ b/app/assets/javascripts/angularjs/build_lists/build_lists_controller.js.erb @@ -68,6 +68,7 @@ function($scope, BuildListsService, $location, $interval, $uibModal) { $scope.total_items = res.total_items; $location.search(Object.assign(filter, res.filter)); $scope.per_page = filter.per_page; + $scope.server_status = res.server_status; $scope.isRequest = false; }); } @@ -138,7 +139,6 @@ function($scope, BuildListsService, $location, $interval, $uibModal) { RosaABF.controller('FiltersInstanceController', ['$scope', '$uibModalInstance', 'params', function($scope, $uibModalInstance, params) { - console.log(params); $scope.params = params; $scope.apply = function() { diff --git a/app/assets/javascripts/angularjs/controllers/statistics_controller.js.coffee b/app/assets/javascripts/angularjs/controllers/statistics_controller.js.coffee index 0db135a94..83d4244fb 100644 --- a/app/assets/javascripts/angularjs/controllers/statistics_controller.js.coffee +++ b/app/assets/javascripts/angularjs/controllers/statistics_controller.js.coffee @@ -65,7 +65,7 @@ RosaABF.controller 'StatisticsController', ['$scope', '$http', '$timeout', ($sco range_end: $scope.range_end users_or_groups: $scope.users_or_groups format: 'json' - console.log($scope.users_or_groups) + $http.get($scope.statistics_path, params: params).success (results) -> $scope.statistics = results diff --git a/app/assets/javascripts/angularjs/models/build_list.js.erb b/app/assets/javascripts/angularjs/models/build_list.js.erb index 16ed077ac..6f3315a33 100644 --- a/app/assets/javascripts/angularjs/models/build_list.js.erb +++ b/app/assets/javascripts/angularjs/models/build_list.js.erb @@ -37,7 +37,6 @@ var BuildList = function(atts, dictionary) { self.version_link_url = Routes.commit_path(self.project.name_with_owner, self.version_link_text); } self.project.url = Routes.project_build_lists_path(self.project.name_with_owner); - console.log(self.project.url); } if (self.user) diff --git a/app/assets/javascripts/angularjs/services/build_lists_service.js.erb b/app/assets/javascripts/angularjs/services/build_lists_service.js.erb index 3594172ab..6435a50e1 100644 --- a/app/assets/javascripts/angularjs/services/build_lists_service.js.erb +++ b/app/assets/javascripts/angularjs/services/build_lists_service.js.erb @@ -68,7 +68,8 @@ angular.module("RosaABF").factory('BuildListsService', ["$http", function($http) build_lists: build_lists_final, page: results.data.page, total_items: results.data.total_items, - filter: results.data.filter + filter: results.data.filter, + server_status: results.data.server_status }; }); } diff --git a/app/controllers/projects/build_lists_controller.rb b/app/controllers/projects/build_lists_controller.rb index ee4eabbf8..bf0330fe6 100644 --- a/app/controllers/projects/build_lists_controller.rb +++ b/app/controllers/projects/build_lists_controller.rb @@ -35,7 +35,7 @@ class Projects::BuildListsController < Projects::BaseController :source_packages, project: :project_statistics) - #@build_server_status = AbfWorkerStatusPresenter.new.projects_status + @build_server_status = AbfWorkerStatusPresenter.new.projects_status end end end diff --git a/app/controllers/projects/projects_controller.rb b/app/controllers/projects/projects_controller.rb index 0c784ea73..30ff67dd5 100644 --- a/app/controllers/projects/projects_controller.rb +++ b/app/controllers/projects/projects_controller.rb @@ -69,7 +69,7 @@ class Projects::ProjectsController < Projects::BaseController if @project.save flash[:notice] = t('flash.project.saved') - redirect_to @project + redirect_to project_build_lists_path(@project) else flash[:error] = t('flash.project.save_error') flash[:warning] = @project.errors.full_messages.join('. ') diff --git a/app/presenters/abf_worker_status_presenter.rb b/app/presenters/abf_worker_status_presenter.rb index 74f6f9c35..732280a39 100644 --- a/app/presenters/abf_worker_status_presenter.rb +++ b/app/presenters/abf_worker_status_presenter.rb @@ -4,56 +4,21 @@ class AbfWorkerStatusPresenter end def projects_status - Rails.cache.fetch([AbfWorkerStatusPresenter, :projects_status], expires_in: 10.seconds) do - result = get_status(:rpm, :publish) { |w, worker| w.to_s =~ /#{worker}_worker_default/ } + Rails.cache.fetch([AbfWorkerStatusPresenter, :projects_status], expires_in: 30.seconds) do + result = {rpm: {}} nodes = RpmBuildNode.total_statistics - result[:rpm][:workers] += nodes[:systems] - result[:rpm][:build_tasks] += nodes[:busy] + result[:rpm][:workers] = nodes[:systems] + result[:rpm][:build_tasks] = nodes[:busy] result[:rpm][:other_workers] = nodes[:others] - external_bls = BuildList.for_status(BuildList::BUILD_PENDING).external_nodes(:everything).count - result[:rpm][:default_tasks] += external_bls + count_of_tasks('user_build_') + normal_pending = BuildList.for_status(BuildList::BUILD_PENDING).where(mass_build_id: nil).count + mass_build_pending = BuildList.for_status(BuildList::BUILD_PENDING).where.not(mass_build_id: nil).count + + result[:rpm][:pending] = normal_pending + result[:rpm][:mass_build_pending] = mass_build_pending - mass_build_tasks = count_of_tasks('mass_build_') - result[:rpm][:low_tasks] += mass_build_tasks - result[:rpm][:tasks] += external_bls + mass_build_tasks result end end - def products_status - get_status(:iso) { |w, worker| - str = w.to_s - str =~ /iso_worker/ && str !~ /observer/ - } - end - - protected - - def count_of_tasks(regexp) - Redis.current.smembers('resque:queues'). - select{ |q| q =~ /#{regexp}/ }. - map{ |q| Redis.current.llen("resque:queue:#{q}") }.sum - end - - 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) - key = "resque:queue:#{worker}_worker" - default_tasks, tasks = Redis.current.llen("#{key}_default"), Redis.current.llen(key) - { - workers: workers.count, - build_tasks: workers.select{ |w| w.working? }.count, - default_tasks: default_tasks, - low_tasks: tasks, - tasks: (default_tasks + tasks) - } - end end diff --git a/app/views/projects/build_lists/_server_status.html.slim b/app/views/projects/build_lists/_server_status.html.slim index 8fe69893a..0c019115c 100644 --- a/app/views/projects/build_lists/_server_status.html.slim +++ b/app/views/projects/build_lists/_server_status.html.slim @@ -1,32 +1,20 @@ -ul.nav.navbar-nav.navbar-left - li.bg-success - a.no-pointer href='' - i.fa.fa-info-circle.fa-lg.text-primary - =< t 'layout.build_lists.build_server_status.rpm_workers' - ' : - => t 'layout.build_lists.build_server_status.abf' - span.badge.bg-primary[] {{server_status.rpm.workers}} - =<> t 'layout.build_lists.build_server_status.custom' - span.badge.bg-primary[] {{server_status.rpm.other_workers}} - - li.bg-info - a.no-pointer href='' - = t('layout.build_lists.build_server_status.tasks').mb_chars.capitalize - ' : - => t 'layout.build_lists.build_server_status.custom' - span.badge.bg-primary[] {{server_status.rpm.default_tasks}} - =<> t 'layout.build_lists.build_server_status.mass_build_tasks' - span.badge.bg-primary[] {{server_status.rpm.low_tasks}} - =<> t 'layout.build_lists.build_server_status.build_tasks' - span.badge.bg-primary[] {{server_status.rpm.build_tasks}} - - li.bg-warning - a.no-pointer href='' - = t 'layout.build_lists.build_server_status.publish_workers' - ' : - => t 'layout.build_lists.build_server_status.amount' - span.badge.bg-primary[] {{server_status.publish.workers}} - =<> t 'layout.build_lists.build_server_status.tasks' - span.badge.bg-primary[] {{server_status.publish.tasks}} - =<> t 'layout.build_lists.build_server_status.build_tasks' - span.badge.bg-primary[] {{server_status.publish.build_tasks}} +.well.well-sm + = t('layout.build_lists.build_server_status.rpm_workers') + | : + => t('layout.build_lists.build_server_status.abf') + span.badge + | {{::server_status.rpm.workers}} + =<> t 'layout.build_lists.build_server_status.custom' + span.badge + | {{::server_status.rpm.other_workers}} + =< t('layout.build_lists.build_server_status.tasks').mb_chars.capitalize + | : + =<> t('layout.build_lists.build_server_status.custom') + span.badge + | {{::server_status.rpm.pending}} + =<> t 'layout.build_lists.build_server_status.mass_build_tasks' + span.badge + | {{::server_status.rpm.mass_build_pending}} + =<> t('layout.build_lists.build_server_status.build_tasks') + span.badge + | {{::server_status.rpm.build_tasks}} \ No newline at end of file diff --git a/app/views/projects/build_lists/index.html.slim b/app/views/projects/build_lists/index.html.slim index fa4b327e6..a2b666042 100644 --- a/app/views/projects/build_lists/index.html.slim +++ b/app/views/projects/build_lists/index.html.slim @@ -1,5 +1,6 @@ .row.top-space .col-md-12 ng-controller="BuildListsController" ng-init=('getBuildLists("'+params[:name_with_owner].to_s+'")') + == render 'projects/build_lists/server_status' == render 'projects/build_lists/filter' rd-widget rd-widget-header title="Build Lists {{::widgetTitle}}" icon="fa-gears"