Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SAT-30393 - Skip recurring logic tasks if on prem is enabled #941

Merged
merged 1 commit into from
Jan 22, 2025

Conversation

chris1984
Copy link
Member

@chris1984 chris1984 commented Jan 14, 2025

This PR adds a skip to inventory/insights/generate report scheduled sync tasks if on_prem is enabled. This includes a change @jeremylenz has in his pr, once that is merged, I will remove it from here.

Copy link
Collaborator

@jeremylenz jeremylenz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I notice this approach just skips planning the scheduled sync tasks if we're using the local advisor engine. This should work fine, but you'd still see actions in Dynflow that are empty and successful.

Another option is to avoid scheduling them at all here -->

ForemanRhCloud::Engine.register_scheduled_task(InsightsCloud::Async::InsightsScheduledSync, '0 0 * * *')

But that may be a bit less safe because of where and when ForemanRhCloud.with_local_advisor_engine? is defined..? I'm a bit unclear on if that will work, but if it does it seems cleaner to me.

@ShimShtein @parthaa thoughts?

@parthaa
Copy link
Collaborator

parthaa commented Jan 14, 2025

I notice this approach just skips planning the scheduled sync tasks if we're using the local advisor engine. This should work fine, but you'd still see actions in Dynflow that are empty and successful.

While I agree you'd rather not have tasks scheduled if not needed. I am thinking in the future when we may want the hybrid option. I have a feeling we are better of scheduling but skipping.

@parthaa
Copy link
Collaborator

parthaa commented Jan 20, 2025

Hmm how about a seed file that has this logic so that we disable the recurring task rather than just returning.

if ForemanRhCloud.with_local_advisor_engine?
  ::ForemanTasks::RecurringLogic.joins(:tasks).where(tasks: { label: ["InventorySync::Async::InventoryScheduledSync", "ForemanInventoryUpload::Async::GenerateAllReportsJob", "InsightsCloud::Async::InsightsScheduledSync"] }, state: "active").distinct(:id).each {|logic| logic.update!(enabled: false)}
end

@jeremylenz
Copy link
Collaborator

Do we support turning local off after it's on? if so, we may want to do it both ways (e.g. enable or disable the logic.)

@chris1984
Copy link
Member Author

Do we support turning local off after it's on? if so, we may want to do it both ways (e.g. enable or disable the logic.)

We do support that with the installer flag setting it to false, we can't do this in a seed file then. We would have to do something in the engine rb right @parthaa

@jeremylenz
Copy link
Collaborator

Side question: Why disable the insights scheduled sync one? Wouldn't that just go to the local iop-advisor-engine?

@chris1984
Copy link
Member Author

Side question: Why disable the insights scheduled sync one? Wouldn't that just go to the local iop-advisor-engine?

Fair point, I was just doing it since the engine writes to the api and we modify the DB right then. There is no harm in having it sync to the engine. Will take that out of the pr.

@jeremylenz
Copy link
Collaborator

the engine writes to the api and we modify the DB right then. There is no harm in having it sync to the engine.

If it's also not doing anything useful, that'd be an argument for disabling it as well.

Copy link
Collaborator

@parthaa parthaa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

APJ. I thought about disabling tasks when advisor is on but feel its not worth the complexity and having to deal with enabling tasks when user decides to turn the advisor off.

@chris1984 chris1984 force-pushed the iop-tasks branch 3 times, most recently from a8d654d to 9612308 Compare January 21, 2025 21:05
@chris1984 chris1984 force-pushed the iop-tasks branch 2 times, most recently from bbed72e to 74ab798 Compare January 22, 2025 16:12
@chris1984
Copy link
Member Author

Working correctly now
screenshot-ip-10-0-167-73 rhos-01 prod psi rdu2 redhat com-2025 01 22-10_27_46

@chris1984 chris1984 requested a review from parthaa January 22, 2025 16:24
@parthaa
Copy link
Collaborator

parthaa commented Jan 22, 2025

Works well. ACK

@parthaa
Copy link
Collaborator

parthaa commented Jan 22, 2025

Recommended patch

diff --git a/test/jobs/inventory_scheduled_sync_test.rb b/test/jobs/inventory_scheduled_sync_test.rb
index 338d900..48a2f88 100644
--- a/test/jobs/inventory_scheduled_sync_test.rb
+++ b/test/jobs/inventory_scheduled_sync_test.rb
@@ -15,13 +15,12 @@ class InventoryScheduledSyncTest < ActiveSupport::TestCase
   end
 
   test 'Skips execution if with_local_advisor_engine? is true' do
-    Setting[:allow_auto_inventory_upload] = true
-
     ForemanRhCloud.stubs(:with_local_advisor_engine?).returns(true)
-
     InventorySync::Async::InventoryScheduledSync.any_instance.expects(:plan_org_sync).never
 
-    ForemanTasks.sync_task(InventorySync::Async::InventoryScheduledSync)
+    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

@chris1984 chris1984 merged commit 6ce3e76 into theforeman:develop Jan 22, 2025
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants