diff --git a/app/admin/node_instructions.rb b/app/admin/node_instructions.rb index 0f2e0fab5..bfa18ea15 100644 --- a/app/admin/node_instructions.rb +++ b/app/admin/node_instructions.rb @@ -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}?") diff --git a/app/controllers/api/v1/jobs_controller.rb b/app/controllers/api/v1/jobs_controller.rb index 73af36564..e634efc08 100644 --- a/app/controllers/api/v1/jobs_controller.rb +++ b/app/controllers/api/v1/jobs_controller.rb @@ -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 diff --git a/app/jobs/restart_nodes_job.rb b/app/jobs/restart_nodes_job.rb new file mode 100644 index 000000000..e158cf3a0 --- /dev/null +++ b/app/jobs/restart_nodes_job.rb @@ -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 diff --git a/app/models/node_instruction.rb b/app/models/node_instruction.rb index 2fcfc2d7a..24ac3509b 100644 --- a/app/models/node_instruction.rb +++ b/app/models/node_instruction.rb @@ -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 diff --git a/app/views/projects/build_lists/show.json.jbuilder b/app/views/projects/build_lists/show.json.jbuilder index 03a1a6d98..1f723f807 100644 --- a/app/views/projects/build_lists/show.json.jbuilder +++ b/app/views/projects/build_lists/show.json.jbuilder @@ -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) diff --git a/config/resque_schedule.yml b/config/resque_schedule.yml index 44b2dfac2..fbdade941 100644 --- a/config/resque_schedule.yml +++ b/config/resque_schedule.yml @@ -24,4 +24,11 @@ clean_api_defender_statistics: - '1d' class: 'CleanApiDefenderStatisticsJob' queue: clone_build - description: 'Cleans ApiDefender statistics' \ No newline at end of file + description: 'Cleans ApiDefender statistics' + +restart_nodes: + every: + - '5m' + class: 'RestartNodesJob' + queue: hook + description: 'Restarts unavailable nodes' \ No newline at end of file