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 14, 2025
1 parent d8d9703 commit 69ca4ab
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 "with_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"
Expand Down
4 changes: 4 additions & 0 deletions lib/foreman_rh_cloud/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -193,4 +193,8 @@ def self.register_scheduled_task(task_class, cronline)
end
end
end

def self.with_local_advisor_engine?
SETTINGS.dig(:foreman_rh_cloud, :use_local_advisor_engine) || false
end
end
7 changes: 7 additions & 0 deletions lib/insights_cloud/async/insights_scheduled_sync.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@ class InsightsScheduledSync < ::Actions::EntryAction
include ForemanInventoryUpload::Async::DelayedStart

def plan
if ForemanRhCloud.with_local_advisor_engine?
logger.debug(
'The scheduled process is disabled due to the "with_local_advisor_engine"
SETTING being set to true.'
)
return
end
unless Setting[:allow_auto_insights_sync]
logger.debug(
'The scheduled process is disabled due to the "allow_auto_insights_sync"
Expand Down
7 changes: 7 additions & 0 deletions lib/inventory_sync/async/inventory_scheduled_sync.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@ class InventoryScheduledSync < ::Actions::EntryAction
include ForemanInventoryUpload::Async::DelayedStart

def plan
if ForemanRhCloud.with_local_advisor_engine?
logger.debug(
'The scheduled process is disabled due to the "with_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"
Expand Down
12 changes: 12 additions & 0 deletions test/jobs/inventory_scheduled_sync_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ class InventoryScheduledSyncTest < ActiveSupport::TestCase
include ForemanTasks::TestHelpers::WithInThreadExecutor

test 'Schedules an execution if auto upload is enabled' do
Setting[:use_local_advisor_engine] = false
Setting[:allow_auto_inventory_upload] = true
Setting[:allow_auto_insights_mismatch_delete] = true

Expand All @@ -16,6 +17,7 @@ class InventoryScheduledSyncTest < ActiveSupport::TestCase

test 'Skips execution if auto upload is disabled' do
Setting[:allow_auto_inventory_upload] = false
Setting[:use_local_advisor_engine] = false

InventorySync::Async::InventoryScheduledSync.any_instance.expects(:plan_org_sync).never

Expand All @@ -25,10 +27,20 @@ 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
Setting[:use_local_advisor_engine] = 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

ForemanTasks.sync_task(InventorySync::Async::InventoryScheduledSync)
end

test 'Skips execution if local advisor engine is enabled' do
Setting[:allow_auto_inventory_upload] = false
Setting[:use_local_advisor_engine] = true

InventorySync::Async::InventoryScheduledSync.any_instance.expects(:plan_org_sync).never

ForemanTasks.sync_task(InventorySync::Async::InventoryScheduledSync)
end
end

0 comments on commit 69ca4ab

Please sign in to comment.