From a8d654dc031ca36269a4a0da731b4240c38eee47 Mon Sep 17 00:00:00 2001 From: Chris Roberts Date: Tue, 14 Jan 2025 12:01:41 -0500 Subject: [PATCH] SAT-30393 - Skip recurring logic tasks if on prem is enabled --- .../async/generate_all_reports_job.rb | 37 +++++++++++++------ .../async/insights_scheduled_sync.rb | 12 +++++- .../async/inventory_scheduled_sync.rb | 22 +++++++---- test/jobs/inventory_scheduled_sync_test.rb | 2 + 4 files changed, 53 insertions(+), 20 deletions(-) diff --git a/lib/foreman_inventory_upload/async/generate_all_reports_job.rb b/lib/foreman_inventory_upload/async/generate_all_reports_job.rb index ba71fb93..b7fdc5fc 100644 --- a/lib/foreman_inventory_upload/async/generate_all_reports_job.rb +++ b/lib/foreman_inventory_upload/async/generate_all_reports_job.rb @@ -5,6 +5,13 @@ class GenerateAllReportsJob < ::Actions::EntryAction include ForemanInventoryUpload::Async::DelayedStart def plan + if ForemanRhCloud.with_local_advisor_engine? + logger.debug( + 'The scheduled process is disabled due to the "use_local_advisor_engine" + SETTING being set to true.' + ) + return + end unless Setting[:allow_auto_inventory_upload] logger.debug( 'The scheduled process is disabled due to the "allow_auto_inventory_upload" @@ -13,20 +20,28 @@ def plan return end - after_delay do - organizations = Organization.unscoped.all + # rubocop:disable Style/GuardClause + unless ForemanRhCloud.with_local_advisor_engine? + after_delay do + organizations = Organization.unscoped.all - organizations.map do |organization| - total_hosts = ForemanInventoryUpload::Generators::Queries.for_org(organization.id, use_batches: false).count + organizations.map do |organization| + total_hosts = ForemanInventoryUpload::Generators::Queries.for_org(organization.id, use_batches: false).count - if total_hosts <= ForemanInventoryUpload.max_org_size - disconnected = false - plan_generate_report(ForemanInventoryUpload.generated_reports_folder, organization, disconnected) - else - logger.info("Skipping automatic uploads for organization #{organization.name}, too many hosts (#{total_hosts}/#{ForemanInventoryUpload.max_org_size})") - end - end.compact + if total_hosts <= ForemanInventoryUpload.max_org_size + disconnected = false + plan_generate_report(ForemanInventoryUpload.generated_reports_folder, organization, disconnected) + else + logger.info("Skipping automatic uploads for organization #{organization.name}, too many hosts (#{total_hosts}/#{ForemanInventoryUpload.max_org_size})") + end + end.compact + end end + # rubocop:enable Style/GuardClause + end + + def run + output[:status] = _('The scheduled process is disabled because this Foreman is configured with the use_local_advisor_engine option.') if ForemanRhCloud.with_local_advisor_engine? end def rescue_strategy_for_self diff --git a/lib/insights_cloud/async/insights_scheduled_sync.rb b/lib/insights_cloud/async/insights_scheduled_sync.rb index c90f5b80..b985fdac 100644 --- a/lib/insights_cloud/async/insights_scheduled_sync.rb +++ b/lib/insights_cloud/async/insights_scheduled_sync.rb @@ -13,9 +13,17 @@ def plan return end - after_delay do - plan_full_sync + # rubocop:disable Style/GuardClause + unless ForemanRhCloud.with_local_advisor_engine? + after_delay do + plan_full_sync + end end + # rubocop:enable Style/GuardClause + end + + def run + output[:status] = _('The scheduled process is disabled because this Foreman is configured with the use_local_advisor_engine option.') if ForemanRhCloud.with_local_advisor_engine? end def plan_full_sync diff --git a/lib/inventory_sync/async/inventory_scheduled_sync.rb b/lib/inventory_sync/async/inventory_scheduled_sync.rb index f0c25d86..8a5c0a6a 100644 --- a/lib/inventory_sync/async/inventory_scheduled_sync.rb +++ b/lib/inventory_sync/async/inventory_scheduled_sync.rb @@ -13,23 +13,31 @@ def plan return end - after_delay do - # perform a sequence of sync then delete in parallel for all organizations - concurrence do - Organization.unscoped.each do |org| - sequence do - plan_org_sync(org) - plan_remove_insights_hosts(org.id) if Setting[:allow_auto_insights_mismatch_delete] + # rubocop:disable Style/GuardClause + unless ForemanRhCloud.with_local_advisor_engine? + after_delay do + # perform a sequence of sync then delete in parallel for all organizations + concurrence do + Organization.unscoped.each do |org| + sequence do + plan_org_sync(org) + plan_remove_insights_hosts(org.id) if Setting[:allow_auto_insights_mismatch_delete] + end end end end end + # rubocop:enable Style/GuardClause end def plan_org_sync(org) plan_action InventoryFullSync, org end + def run + output[:status] = _('The scheduled process is disabled because this Foreman is configured with the use_local_advisor_engine option.') if ForemanRhCloud.with_local_advisor_engine? + end + def plan_remove_insights_hosts(org_id) # plan a remove hosts action with search set to empty (all records) plan_action(ForemanInventoryUpload::Async::RemoveInsightsHostsJob, '', org_id) diff --git a/test/jobs/inventory_scheduled_sync_test.rb b/test/jobs/inventory_scheduled_sync_test.rb index 73e09488..e4ca7a83 100644 --- a/test/jobs/inventory_scheduled_sync_test.rb +++ b/test/jobs/inventory_scheduled_sync_test.rb @@ -7,6 +7,7 @@ class InventoryScheduledSyncTest < ActiveSupport::TestCase test 'Schedules an execution if auto upload is enabled' do Setting[:allow_auto_inventory_upload] = true Setting[:allow_auto_insights_mismatch_delete] = true + ForemanRhCloud.stubs(:with_local_advisor_engine?).returns(false) InventorySync::Async::InventoryScheduledSync.any_instance.expects(:plan_org_sync).times(Organization.unscoped.count) InventorySync::Async::InventoryScheduledSync.any_instance.expects(:plan_remove_insights_hosts).times(Organization.unscoped.count) @@ -25,6 +26,7 @@ class InventoryScheduledSyncTest < ActiveSupport::TestCase test 'Skips mismatch deletion if the setting is disabled' do Setting[:allow_auto_inventory_upload] = true Setting[:allow_auto_insights_mismatch_delete] = false + ForemanRhCloud.stubs(:with_local_advisor_engine?).returns(false) InventorySync::Async::InventoryScheduledSync.any_instance.expects(:plan_org_sync).times(Organization.unscoped.count) InventorySync::Async::InventoryScheduledSync.any_instance.expects(:plan_remove_insights_hosts).never