Remove old abandoned bubble creations via cron
This commit is contained in:
@@ -0,0 +1,7 @@
|
||||
class RemoveAbandonedCreationsJob < ApplicationJob
|
||||
queue_as :default
|
||||
|
||||
def perform
|
||||
Bubble.remove_abandoned_creations
|
||||
end
|
||||
end
|
||||
@@ -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
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user