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 01f3c72
Show file tree
Hide file tree
Showing 5 changed files with 34 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 "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"
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 "use_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 "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"
Expand Down
9 changes: 9 additions & 0 deletions test/jobs/inventory_scheduled_sync_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,13 @@ class InventoryScheduledSyncTest < ActiveSupport::TestCase

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

test 'Skips execution if local advisor engine is enabled' do
Setting[:allow_auto_inventory_upload] = false
ForemanRhCloud.stubs(:with_local_advisor_engine?).returns(true)

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

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

0 comments on commit 01f3c72

Please sign in to comment.