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..6aa8f464 100644 --- a/lib/foreman_inventory_upload/async/generate_all_reports_job.rb +++ b/lib/foreman_inventory_upload/async/generate_all_reports_job.rb @@ -13,22 +13,30 @@ def plan return end - after_delay do - organizations = Organization.unscoped.all - - 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 ForemanRhCloud.with_local_advisor_engine? + plan_self # so that 'run' runs + else + after_delay do + organizations = Organization.unscoped.all + + 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 + end end 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 Dynflow::Action::Rescue::Fail end diff --git a/lib/insights_cloud/async/insights_scheduled_sync.rb b/lib/insights_cloud/async/insights_scheduled_sync.rb index c90f5b80..10a11c42 100644 --- a/lib/insights_cloud/async/insights_scheduled_sync.rb +++ b/lib/insights_cloud/async/insights_scheduled_sync.rb @@ -13,11 +13,19 @@ def plan return end - after_delay do - plan_full_sync + if ForemanRhCloud.with_local_advisor_engine? + plan_self + else + after_delay do + plan_full_sync # so that 'run' runs + end end 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 plan_action(InsightsFullSync, Organization.unscoped.all) end diff --git a/lib/inventory_sync/async/inventory_scheduled_sync.rb b/lib/inventory_sync/async/inventory_scheduled_sync.rb index f0c25d86..f1b7701e 100644 --- a/lib/inventory_sync/async/inventory_scheduled_sync.rb +++ b/lib/inventory_sync/async/inventory_scheduled_sync.rb @@ -13,13 +13,17 @@ 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] + if ForemanRhCloud.with_local_advisor_engine? + plan_self # so that 'run' runs + else + 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 @@ -30,6 +34,10 @@ 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..c074b078 100644 --- a/test/jobs/inventory_scheduled_sync_test.rb +++ b/test/jobs/inventory_scheduled_sync_test.rb @@ -14,6 +14,16 @@ class InventoryScheduledSyncTest < ActiveSupport::TestCase ForemanTasks.sync_task(InventorySync::Async::InventoryScheduledSync) end + test 'Skips execution if with_local_advisor_engine? is true' do + ForemanRhCloud.stubs(:with_local_advisor_engine?).returns(true) + + InventorySync::Async::InventoryScheduledSync.any_instance.expects(:plan_org_sync).never + + task = ForemanTasks.sync_task(InventorySync::Async::InventoryScheduledSync) + status = task.output[:status].to_s + assert_match(/Foreman is configured with the use_local_advisor_engine option/, status) + end + test 'Skips execution if auto upload is disabled' do Setting[:allow_auto_inventory_upload] = false