From bd6e83fee879b8960986ed107514b960a5309c81 Mon Sep 17 00:00:00 2001 From: Ivan Necas Date: Wed, 25 Apr 2018 16:07:33 +0200 Subject: [PATCH] Fixes #20661 - use separate queue for rex jobs (#330) --- app/lib/actions/remote_execution/run_host_job.rb | 4 ++++ app/lib/actions/remote_execution/run_hosts_job.rb | 4 ++++ app/models/setting/remote_execution.rb | 10 +++++++--- lib/foreman_remote_execution/engine.rb | 3 +++ 4 files changed, 18 insertions(+), 3 deletions(-) diff --git a/app/lib/actions/remote_execution/run_host_job.rb b/app/lib/actions/remote_execution/run_host_job.rb index 59210ca47..9b507a37c 100644 --- a/app/lib/actions/remote_execution/run_host_job.rb +++ b/app/lib/actions/remote_execution/run_host_job.rb @@ -7,6 +7,10 @@ class RunHostJob < Actions::EntryAction middleware.do_not_use Dynflow::Middleware::Common::Transaction middleware.use Actions::Middleware::HideSecrets + def queue + ForemanRemoteExecution::DYNFLOW_QUEUE + end + def resource_locks :link end diff --git a/app/lib/actions/remote_execution/run_hosts_job.rb b/app/lib/actions/remote_execution/run_hosts_job.rb index 0b7fb9cc3..fa8571569 100644 --- a/app/lib/actions/remote_execution/run_hosts_job.rb +++ b/app/lib/actions/remote_execution/run_hosts_job.rb @@ -8,6 +8,10 @@ class RunHostsJob < Actions::ActionWithSubPlans middleware.use Actions::Middleware::BindJobInvocation middleware.use Actions::Middleware::RecurringLogic + def queue + ForemanRemoteExecution::DYNFLOW_QUEUE + end + def delay(delay_options, job_invocation) task.add_missing_task_groups(job_invocation.task_group) job_invocation.targeting.resolve_hosts! if job_invocation.targeting.static? && !job_invocation.targeting.resolved? diff --git a/app/models/setting/remote_execution.rb b/app/models/setting/remote_execution.rb index 09d96b6df..e95c300d9 100644 --- a/app/models/setting/remote_execution.rb +++ b/app/models/setting/remote_execution.rb @@ -2,7 +2,7 @@ class Setting::RemoteExecution < Setting ::Setting::BLANK_ATTRS.concat %w{remote_execution_ssh_password remote_execution_ssh_key_passphrase} - # rubocop:disable Metrics/MethodLength + # rubocop:disable Metrics/MethodLength,Metrics/AbcSize def self.load_defaults # Check the table exists return unless super @@ -63,12 +63,16 @@ def self.load_defaults nil, N_('Default SSH key passphrase'), nil, - { :encrypted => true }) + { :encrypted => true }), + self.set('remote_execution_workers_pool_size', + N_('Amount of workers in the pool to handle the execution of the remote execution jobs. Restart of the dynflowd/foreman-tasks service is required.'), + 5, + N_('Workers pool size')) ].each { |s| self.create! s.update(:category => 'Setting::RemoteExecution') } end true end # rubocop:enable AbcSize - # rubocop:enable Metrics/MethodLength + # rubocop:enable Metrics/MethodLength,Metrics/AbcSize end diff --git a/lib/foreman_remote_execution/engine.rb b/lib/foreman_remote_execution/engine.rb index 548bdbef3..5b6cda937 100644 --- a/lib/foreman_remote_execution/engine.rb +++ b/lib/foreman_remote_execution/engine.rb @@ -1,6 +1,8 @@ require 'foreman_remote_execution_core' module ForemanRemoteExecution + DYNFLOW_QUEUE = :remote_execution + class Engine < ::Rails::Engine engine_name 'foreman_remote_execution' @@ -26,6 +28,7 @@ class Engine < ::Rails::Engine initializer 'foreman_remote_execution.require_dynflow', :before => 'foreman_tasks.initialize_dynflow' do |app| ForemanTasks.dynflow.require! + ForemanTasks.dynflow.config.queues.add(DYNFLOW_QUEUE, :pool_size => Setting['remote_execution_workers_pool_size']) if Setting.table_exists? rescue(false) ForemanTasks.dynflow.config.eager_load_paths << File.join(ForemanRemoteExecution::Engine.root, 'app/lib/actions') end