Skip to content

Commit

Permalink
correctly register REX features when booting the app (#904)
Browse files Browse the repository at this point in the history
  • Loading branch information
evgeni authored Sep 24, 2024
1 parent 0b1bfda commit 101ac3b
Showing 1 changed file with 36 additions and 36 deletions.
72 changes: 36 additions & 36 deletions lib/foreman_rh_cloud/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 101ac3b

Please sign in to comment.