Stalled cards are unstalled by anything that touches updated_at

ref: https://app.fizzy.do/5986089/cards/2492
This commit is contained in:
Mike Dalessio
2025-11-18 11:08:27 -05:00
parent 9249199241
commit dbbee2c661
3 changed files with 38 additions and 8 deletions
+4 -3
View File
@@ -7,16 +7,17 @@ module Card::Entropic
.joins(board: :account)
.left_outer_joins(board: :entropy)
.joins("LEFT OUTER JOIN entropies AS account_entropies ON account_entropies.account_id = accounts.id AND account_entropies.container_type = 'Account' AND account_entropies.container_id = accounts.id")
.where("last_active_at <= DATE_SUB(NOW(), INTERVAL COALESCE(entropies.auto_postpone_period, account_entropies.auto_postpone_period) SECOND)")
.where("last_active_at <= DATE_SUB(?, INTERVAL COALESCE(entropies.auto_postpone_period, account_entropies.auto_postpone_period) SECOND)", Time.now)
end
scope :postponing_soon, -> do
now = Time.now
active
.joins(board: :account)
.left_outer_joins(board: :entropy)
.joins("LEFT OUTER JOIN entropies AS account_entropies ON account_entropies.account_id = accounts.id AND account_entropies.container_type = 'Account' AND account_entropies.container_id = accounts.id")
.where("last_active_at > DATE_SUB(NOW(), INTERVAL COALESCE(entropies.auto_postpone_period, account_entropies.auto_postpone_period) SECOND)")
.where("last_active_at <= DATE_SUB(NOW(), INTERVAL CAST(COALESCE(entropies.auto_postpone_period, account_entropies.auto_postpone_period) * 0.75 AS SIGNED) SECOND)")
.where("last_active_at > DATE_SUB(?, INTERVAL COALESCE(entropies.auto_postpone_period, account_entropies.auto_postpone_period) SECOND)", now)
.where("last_active_at <= DATE_SUB(?, INTERVAL CAST(COALESCE(entropies.auto_postpone_period, account_entropies.auto_postpone_period) * 0.75 AS SIGNED) SECOND)", now)
end
delegate :auto_postpone_period, to: :board
+4 -2
View File
@@ -7,14 +7,16 @@ module Card::Stallable
has_one :activity_spike, class_name: "Card::ActivitySpike", dependent: :destroy
scope :with_activity_spikes, -> { joins(:activity_spike) }
scope :stalled, -> { open.active.with_activity_spikes.where("card_activity_spikes.updated_at": ..STALLED_AFTER_LAST_SPIKE_PERIOD.ago) }
scope :stalled, -> { open.active.with_activity_spikes.where("card_activity_spikes.updated_at": ..STALLED_AFTER_LAST_SPIKE_PERIOD.ago, updated_at: ..STALLED_AFTER_LAST_SPIKE_PERIOD.ago) }
before_update :remember_to_detect_activity_spikes
after_update_commit :detect_activity_spikes_later, if: :should_detect_activity_spikes?
end
def stalled?
open? && last_activity_spike_at < STALLED_AFTER_LAST_SPIKE_PERIOD.ago if activity_spike.present?
if activity_spike.present?
open? && last_activity_spike_at < STALLED_AFTER_LAST_SPIKE_PERIOD.ago && updated_at < STALLED_AFTER_LAST_SPIKE_PERIOD.ago
end
end
def last_activity_spike_at
+30 -3
View File
@@ -20,7 +20,29 @@ class Card::StallableTest < ActiveSupport::TestCase
end
test "a card with an old activity spike is stalled" do
cards(:logo).create_activity_spike!(updated_at: 3.months.ago)
cards(:logo).create_activity_spike!
travel_to 3.months.from_now
assert cards(:logo).stalled?
assert_includes Card.stalled, cards(:logo)
end
test "a stalled card can be unstalled with a single comment" do
cards(:logo).create_activity_spike!
travel_to 3.months.from_now
assert cards(:logo).stalled?
assert_includes Card.stalled, cards(:logo)
cards(:logo).comments.create!(body: "A new comment to unstall the card")
assert_not cards(:logo).stalled?
assert_not_includes Card.stalled, cards(:logo)
# and stalls again after more time passes
travel_to 3.months.from_now
assert cards(:logo).stalled?
assert_includes Card.stalled, cards(:logo)
@@ -28,15 +50,20 @@ class Card::StallableTest < ActiveSupport::TestCase
test "a card with an old activity spike is not stalled after being postponed" do
card = cards(:logo)
card.update!(last_active_at: 1.day.ago - card.board.entropy.auto_postpone_period)
card.create_activity_spike!(updated_at: 3.months.ago)
card.create_activity_spike!
travel_to 3.months.from_now
assert card.stalled?
assert_includes Card.stalled, card
travel_to Time.now + card.board.entropy.auto_postpone_period + 1.day
assert_includes Card.due_to_be_postponed, card
Card.auto_postpone_all_due
assert_not card.reload.stalled?
assert_not_includes Card.stalled, card
end
# More fine-grained testing in Card::ActivitySpike::Detector