Add system to auto reconsider inactive bubbles after 30 days

This commit is contained in:
Jorge Manrubia
2025-04-04 10:04:39 +02:00
parent 08cb69aca5
commit 6f93d4b72a
6 changed files with 46 additions and 3 deletions
@@ -1,4 +1,4 @@
class AutoPopAllDueJob < ApplicationJob
class Bubble::AutoPopAllDueJob < ApplicationJob
queue_as :default
def perform
@@ -0,0 +1,9 @@
class Bubble::AutoReconsiderAllStagnatedJob < ApplicationJob
queue_as :default
def perform
ApplicationRecord.with_each_tenant do |tenant|
Bubble.auto_reconsider_all_stagnated
end
end
end
+16
View File
@@ -1,11 +1,27 @@
module Bubble::Engageable
extend ActiveSupport::Concern
STAGNATED_AFTER = 30.days
included do
has_one :engagement, dependent: :destroy, class_name: "Bubble::Engagement"
scope :doing, -> { active.joins(:engagement) }
scope :considering, -> { active.where.missing(:engagement) }
scope :stagnated, -> { doing.where(last_active_at: ..STAGNATED_AFTER.ago) }
end
class_methods do
def auto_reconsider_all_stagnated
stagnated.find_each do |bubble|
bubble.reconsider
end
end
end
def auto_reconsider_at
last_active_at + STAGNATED_AFTER if last_active_at
end
def doing?
+1 -1
View File
@@ -37,7 +37,7 @@
<span class="card__pop-message">
<% if bubble.doing? %>
Returns to <em>Considering</em> if no activity <%= local_datetime_tag(bubble.auto_pop_at, style: :indays) -%>.
Returns to <em>Considering</em> if no activity <%= local_datetime_tag(bubble.auto_reconsider_at, style: :indays) -%>.
<% else %>
Auto-closes if no activity <%= local_datetime_tag(bubble.auto_pop_at, style: :indays) -%>.
<% end %>
+4 -1
View File
@@ -1,6 +1,9 @@
production:
auto_pop_all_due:
class: AutoPopAllDueJob
class: Bubble::AutoPopAllDueJob
schedule: every hour
auto_reconsider_all_inactive:
class: Bubble::AutoReconsiderAllStagnatedJob
schedule: every hour
remove_abandoned_creations:
class: RemoveAbandonedCreationsJob
+15
View File
@@ -46,4 +46,19 @@ class Bubble::EngageableTest < ActiveSupport::TestCase
assert_includes Bubble.considering, bubbles(:text)
assert_not_includes Bubble.considering, bubbles(:logo)
end
test "auto_reconsider_all_stagnated" do
bubbles(:logo).update!(last_active_at: 1.day.ago - Bubble::Engageable::STAGNATED_AFTER)
bubbles(:logo).engage
bubbles(:shipping).update!(last_active_at: 1.day.from_now - Bubble::Engageable::STAGNATED_AFTER)
bubbles(:shipping).engage
assert_difference -> { Bubble.considering.count }, +1 do
Bubble.auto_reconsider_all_stagnated
end
assert bubbles(:shipping).reload.doing?
assert bubbles(:logo).reload.considering?
end
end