From 101ac3bbfab161c090ceae1b8c54ba9076cb33a1 Mon Sep 17 00:00:00 2001 From: Evgeni Golov Date: Tue, 24 Sep 2024 12:35:25 +0200 Subject: [PATCH] correctly register REX features when booting the app (#904) --- lib/foreman_rh_cloud/engine.rb | 72 +++++++++++++++++----------------- 1 file changed, 36 insertions(+), 36 deletions(-) diff --git a/lib/foreman_rh_cloud/engine.rb b/lib/foreman_rh_cloud/engine.rb index 0e682003..69d3a57a 100644 --- a/lib/foreman_rh_cloud/engine.rb +++ b/lib/foreman_rh_cloud/engine.rb @@ -151,46 +151,46 @@ def self.register_scheduled_task(task_class, cronline) end end - rake_tasks do - Rake::Task['db:seed'].enhance do - ForemanRhCloud::Engine.load_seed - end - end - - initializer 'foreman_rh_cloud.register_rex_features', :before => :finisher_hook do |_app| + initializer 'foreman_rh_cloud.register_scheduled_tasks', :before => :finisher_hook do |_app| # skip database manipulations while tables do not exist, like in migrations - if ActiveRecord::Base.connection.data_source_exists?(ForemanTasks::Task.table_name) - RemoteExecutionFeature.register( - :rh_cloud_remediate_hosts, - N_('Apply Insights recommendations'), - description: N_('Run remediation playbook generated by Insights'), - host_action_button: false - ) - RemoteExecutionFeature.register( - :rh_cloud_connector_run_playbook, - N_('Run RH Cloud playbook'), - description: N_('Run playbook genrated by Red Hat remediations app'), - host_action_button: false, - provided_inputs: ['playbook_url', 'report_url', 'correlation_id', 'report_interval'] - ) - RemoteExecutionFeature.register( - :ansible_configure_cloud_connector, - N_('Configure Cloud Connector on given hosts'), - :description => N_('Configure Cloud Connector on given hosts'), - :proxy_selector_override => ::RemoteExecutionProxySelector::INTERNAL_PROXY - ) - - # skip object creation when admin user is not present, for example in test DB - if User.unscoped.find_by_login(User::ANONYMOUS_ADMIN).present? - ::ForemanTasks.dynflow.config.on_init(false) do |world| - ForemanRhCloud::Engine.register_scheduled_task(ForemanInventoryUpload::Async::GenerateAllReportsJob, '0 0 * * *') - ForemanRhCloud::Engine.register_scheduled_task(InventorySync::Async::InventoryScheduledSync, '0 0 * * *') - ForemanRhCloud::Engine.register_scheduled_task(InsightsCloud::Async::InsightsScheduledSync, '0 0 * * *') - ForemanRhCloud::Engine.register_scheduled_task(InsightsCloud::Async::InsightsClientStatusAging, '0 0 * * *') - end + # skip object creation when admin user is not present, for example in test DB + if ActiveRecord::Base.connection.data_source_exists?(ForemanTasks::Task.table_name) && User.unscoped.find_by_login(User::ANONYMOUS_ADMIN).present? + ::ForemanTasks.dynflow.config.on_init(false) do |world| + ForemanRhCloud::Engine.register_scheduled_task(ForemanInventoryUpload::Async::GenerateAllReportsJob, '0 0 * * *') + ForemanRhCloud::Engine.register_scheduled_task(InventorySync::Async::InventoryScheduledSync, '0 0 * * *') + ForemanRhCloud::Engine.register_scheduled_task(InsightsCloud::Async::InsightsScheduledSync, '0 0 * * *') + ForemanRhCloud::Engine.register_scheduled_task(InsightsCloud::Async::InsightsClientStatusAging, '0 0 * * *') end end rescue ActiveRecord::NoDatabaseError end + + config.to_prepare do + RemoteExecutionFeature.register( + :rh_cloud_remediate_hosts, + N_('Apply Insights recommendations'), + description: N_('Run remediation playbook generated by Insights'), + host_action_button: false + ) + RemoteExecutionFeature.register( + :rh_cloud_connector_run_playbook, + N_('Run RH Cloud playbook'), + description: N_('Run playbook genrated by Red Hat remediations app'), + host_action_button: false, + provided_inputs: ['playbook_url', 'report_url', 'correlation_id', 'report_interval'] + ) + RemoteExecutionFeature.register( + :ansible_configure_cloud_connector, + N_('Configure Cloud Connector on given hosts'), + :description => N_('Configure Cloud Connector on given hosts'), + :proxy_selector_override => ::RemoteExecutionProxySelector::INTERNAL_PROXY + ) + end + + rake_tasks do + Rake::Task['db:seed'].enhance do + ForemanRhCloud::Engine.load_seed + end + end end end