Skip to content

Commit

Permalink
SAT-30393 - Skip recurring logic tasks if on prem is enabled
Browse files Browse the repository at this point in the history
  • Loading branch information
chris1984 committed Jan 21, 2025
1 parent 21aae16 commit 9612308
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 22 deletions.
34 changes: 21 additions & 13 deletions lib/foreman_inventory_upload/async/generate_all_reports_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,28 @@ 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
# 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

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
Expand Down
12 changes: 10 additions & 2 deletions lib/insights_cloud/async/insights_scheduled_sync.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
22 changes: 15 additions & 7 deletions lib/inventory_sync/async/inventory_scheduled_sync.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions test/jobs/inventory_scheduled_sync_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand Down

0 comments on commit 9612308

Please sign in to comment.