Remove old abandoned bubble creations via cron

This commit is contained in:
Kevin McConnell
2025-02-10 14:45:19 +00:00
parent 4121f68f7d
commit bd4e475d44
4 changed files with 28 additions and 10 deletions
@@ -0,0 +1,7 @@
class RemoveAbandonedCreationsJob < ApplicationJob
queue_as :default
def perform
Bubble.remove_abandoned_creations
end
end
+6
View File
@@ -7,6 +7,12 @@ module Bubble::Statuses
scope :published_or_drafted_by, ->(user) { where(status: :published).or(where(status: :drafted, creator: user)) }
end
class_methods do
def remove_abandoned_creations
Bubble.creating.where(updated_at: ..1.day.ago).destroy_all
end
end
def can_recover_abandoned_creation?
abandoned_creations.where(updated_at: 1.day.ago..).any?
end
+4 -10
View File
@@ -1,10 +1,4 @@
# production:
# periodic_cleanup:
# class: CleanSoftDeletedRecordsJob
# queue: background
# args: [ 1000, { batch_size: 500 } ]
# schedule: every hour
# periodic_command:
# command: "SoftDeletedRecord.due.delete_all"
# priority: 2
# schedule: at 5am every day
production:
remove_abandoned_creations:
class: RemoveAbandonedCreationsJob
schedule: every hour
+11
View File
@@ -47,4 +47,15 @@ class Bubble::StatusesTest < ActiveSupport::TestCase
assert_raises(ActiveRecord::RecordNotFound) { bubble_not_edited.reload }
end
test "remove_abandoned_creations" do
bubble_old = buckets(:writebook).bubbles.create! creator: users(:kevin), updated_at: 2.days.ago
bubble_recent = buckets(:writebook).bubbles.create! creator: users(:kevin)
assert_equal 2, Bubble.creating.count
Bubble.remove_abandoned_creations
assert_equal [ bubble_recent ], Bubble.creating
end
end