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 22, 2025
1 parent 21aae16 commit ae01ce1
Show file tree
Hide file tree
Showing 4 changed files with 56 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,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
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,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
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,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
Expand All @@ -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)
Expand Down
10 changes: 10 additions & 0 deletions test/jobs/inventory_scheduled_sync_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit ae01ce1

Please sign in to comment.