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

Add purge_by_date_and_orphaned #23385

Merged
merged 1 commit into from
Mar 20, 2025
Merged

Conversation

kbrock
Copy link
Member

@kbrock kbrock commented Mar 19, 2025

Introduce purging first by date and then by orphanes.

It is not optimal to take 2 arguments, since most purging has stuck to one But both of these need to be passed in.

We could have leveraged these 2 methods separately, but we wanted them to be serialized, and avoid adding a dependency in the queue.

Alternative to #23383 and #23381

Introduce purging first by date and then by orphanes.

It is not optimal to take 2 arguments, since most purging has stuck to one
But both of these need to be passed in.

We could have leveraged these 2 methods separately, but we wanted them to
be serialized, and avoid adding a dependency in the queue.
@@ -11,8 +11,7 @@ def purge_mode_and_value
# remove anything where the resource no longer exists AND
# remove anything older than a certain date
def purge_timer
purge_queue(:orphaned, "resource")
purge_queue(:date, purge_date)
purge_queue(:date_and_orphaned, purge_date, "resource")
Copy link
Member

@jrafanie jrafanie Mar 20, 2025

Choose a reason for hiding this comment

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

Will this work? We're putting both purge_date (used by date) and "resource" (used by orphaned) in the queue args. I see purge_by_date_and_orphaned having a signature older_than, fk_name, window, so I think it will work but maybe it's a bit over engineered.

Copy link
Member

Choose a reason for hiding this comment

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

Maybe we should try using miq_callback? I'll try to draft that to see which is more straight forward.

Copy link
Member

Choose a reason for hiding this comment

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

Trying this locally:

diff --git a/app/models/mixins/purging_mixin.rb b/app/models/mixins/purging_mixin.rb
index bdb7910782..bc9aad7f2b 100644
--- a/app/models/mixins/purging_mixin.rb
+++ b/app/models/mixins/purging_mixin.rb
@@ -63,11 +63,12 @@ module PurgingMixin
       purge_queue(*purge_mode_and_value)
     end

-    def purge_queue(mode, value = nil)
+    def purge_queue(mode, value = nil, callback = nil)
       MiqQueue.submit_job(
-        :class_name  => name,
-        :method_name => "purge_by_#{mode}",
-        :args        => [value]
+        :class_name   => name,
+        :method_name  => "purge_by_#{mode}",
+        :args         => [value],
+        :miq_callback => callback.present? ? callback : nil
       )
     end

diff --git a/app/models/vim_performance_state/purging.rb b/app/models/vim_performance_state/purging.rb
index d3dee077cb..cf6e24d96d 100644
--- a/app/models/vim_performance_state/purging.rb
+++ b/app/models/vim_performance_state/purging.rb
@@ -11,8 +11,12 @@ class VimPerformanceState < ApplicationRecord
       # remove anything where the resource no longer exists AND
       # remove anything older than a certain date
       def purge_timer
-        purge_queue(:orphaned, "resource")
-        purge_queue(:date, purge_date)
+        callback = {
+          :class_name  => name,
+          :method_name => :purge_queue,
+          :args        => [:orphaned, "resource"]
+        }
+        purge_queue(:date, purge_date, callback)
       end

       def purge_window_size

Copy link
Member

Choose a reason for hiding this comment

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

Of course I messed it up in my pseudo code... but I dropped the miq_task and did it through a callback in the original PR: #23383

@jrafanie
Copy link
Member

Merging, we all agree we like this better than #23383 and #23381

@jrafanie jrafanie added the core label Mar 20, 2025
@jrafanie jrafanie merged commit 7811720 into ManageIQ:master Mar 20, 2025
8 checks passed
@kbrock kbrock deleted the purge_date_orphans branch March 21, 2025 13:48
@jrafanie jrafanie mentioned this pull request Mar 25, 2025
17 tasks
@Fryguy
Copy link
Member

Fryguy commented Mar 26, 2025

Backported to spassky in commit 1d94c3f.

commit 1d94c3ffa2ce653806e6007c4b62a750936bb442
Author: Joe Rafaniello <[email protected]>
Date:   Thu Mar 20 14:53:02 2025 -0400

    Merge pull request #23385 from kbrock/purge_date_orphans
    
    Add purge_by_date_and_orphaned
    
    (cherry picked from commit 7811720346f4175f2b762deae6362e3bc7745c9a)

Fryguy pushed a commit that referenced this pull request Mar 26, 2025
Add purge_by_date_and_orphaned

(cherry picked from commit 7811720)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants