#376: added monitoring tool
This commit is contained in:
parent
5b734e3006
commit
552e36cf72
|
@ -49,7 +49,7 @@ ActiveAdmin.register NodeInstruction do
|
|||
|
||||
sidebar 'Actions', only: :show do
|
||||
|
||||
%w(disable ready check restart fail).each do |state|
|
||||
%w(disable ready restart fail).each do |state|
|
||||
div do
|
||||
link_to state.humanize, force_admin_node_instruction_path(resource, state: state), method: :patch
|
||||
end if resource.send("can_#{state}?")
|
||||
|
|
|
@ -9,7 +9,9 @@ class Api::V1::JobsController < Api::V1::BaseController
|
|||
def shift
|
||||
|
||||
@build_list = BuildList.next_build if current_user.system?
|
||||
unless @build_list
|
||||
if @build_list
|
||||
set_builder
|
||||
else
|
||||
platform_ids = Platform.where(name: params[:platforms].split(',')).pluck(:id) if params[:platforms].present?
|
||||
arch_ids = Arch.where(name: params[:arches].split(',')).pluck(:id) if params[:arches].present?
|
||||
build_lists = BuildList.for_status(BuildList::BUILD_PENDING).scoped_to_arch(arch_ids).
|
||||
|
@ -19,36 +21,29 @@ class Api::V1::JobsController < Api::V1::BaseController
|
|||
ActiveRecord::Base.transaction do
|
||||
if current_user.system?
|
||||
@build_list ||= build_lists.external_nodes(:everything).first
|
||||
@build_list.touch if @build_list
|
||||
else
|
||||
@build_list = build_lists.external_nodes(:owned).for_user(current_user).first
|
||||
@build_list ||= build_lists.external_nodes(:everything).
|
||||
accessible_by(current_ability, :everything).readonly(false).first
|
||||
|
||||
if @build_list
|
||||
@build_list.builder = current_user
|
||||
@build_list.save
|
||||
end
|
||||
end
|
||||
set_builder
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
job = {
|
||||
worker_queue: @build_list.worker_queue_with_priority(false),
|
||||
worker_class: @build_list.worker_queue_class,
|
||||
:worker_args => [@build_list.abf_worker_args]
|
||||
} if @build_list
|
||||
|
||||
render json: { job: job }.to_json
|
||||
end
|
||||
|
||||
def statistics
|
||||
if params[:uid].present?
|
||||
RpmBuildNode.create(
|
||||
:id => params[:uid],
|
||||
:user_id => current_user.id,
|
||||
:system => current_user.system?,
|
||||
id: params[:uid],
|
||||
user_id: current_user.id,
|
||||
system: current_user.system?,
|
||||
worker_count: params[:worker_count],
|
||||
busy_workers: params[:busy_workers]
|
||||
) rescue nil
|
||||
|
@ -86,4 +81,12 @@ class Api::V1::JobsController < Api::V1::BaseController
|
|||
end
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
def set_builder
|
||||
return unless @build_list
|
||||
@build_list.builder = current_user
|
||||
@build_list.save
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -0,0 +1,10 @@
|
|||
class RestartNodesJob
|
||||
@queue = :hook
|
||||
|
||||
def self.perform
|
||||
available_nodes = RpmBuildNode.all.map{ |n| n.user_id }.compact.uniq
|
||||
NodeInstruction.where(status: NodeInstruction::READY).
|
||||
where('user_id NOT IN (?)', available_nodes).find_each(&:restart)
|
||||
end
|
||||
|
||||
end
|
|
@ -2,7 +2,6 @@ class NodeInstruction < ActiveRecord::Base
|
|||
STATUSES = [
|
||||
DISABLED = 'disabled',
|
||||
READY = 'ready',
|
||||
CHECKING = 'checking',
|
||||
RESTARTING = 'restarting',
|
||||
FAILED = 'failed'
|
||||
]
|
||||
|
@ -22,23 +21,19 @@ class NodeInstruction < ActiveRecord::Base
|
|||
|
||||
state_machine :status, initial: :ready do
|
||||
event :ready do
|
||||
transition %i(ready restarting disabled failed checking) => :ready
|
||||
transition %i(ready restarting disabled failed) => :ready
|
||||
end
|
||||
|
||||
event :disable do
|
||||
transition ready: :disabled
|
||||
end
|
||||
|
||||
event :check do
|
||||
transition ready: :checking
|
||||
end
|
||||
|
||||
event :restart do
|
||||
transition checking: :restarting
|
||||
transition ready: :restarting
|
||||
end
|
||||
|
||||
event :fail do
|
||||
transition %i(restarting checking) => :failed
|
||||
transition restarting: :failed
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -31,7 +31,7 @@ json.build_list do
|
|||
json.builder do
|
||||
json.fullname @build_list.builder.try(:fullname)
|
||||
json.path user_path(@build_list.builder)
|
||||
end if @build_list.builder
|
||||
end if @build_list.builder && (!@build_list.builder.system? || current_user.admin?)
|
||||
|
||||
json.advisory do
|
||||
json.(@build_list.advisory, :description, :advisory_id)
|
||||
|
|
|
@ -25,3 +25,10 @@ clean_api_defender_statistics:
|
|||
class: 'CleanApiDefenderStatisticsJob'
|
||||
queue: clone_build
|
||||
description: 'Cleans ApiDefender statistics'
|
||||
|
||||
restart_nodes:
|
||||
every:
|
||||
- '5m'
|
||||
class: 'RestartNodesJob'
|
||||
queue: hook
|
||||
description: 'Restarts unavailable nodes'
|
Loading…
Reference in New Issue