feat: clean up old instances automatically

This commit is contained in:
insects 2025-03-12 14:08:04 +01:00
parent 5aa5fe0f5a
commit 070ffa8eeb
8 changed files with 85 additions and 42 deletions

View file

@ -0,0 +1,13 @@
class InstanceCleanupJob < ApplicationJob
queue_as :default
def perform(*args)
instances = Instance.all
to_be_deleted = instances.filter { |i|
# Mark instances older than 2 days for deletion
(Time.now.utc - i.created_at) / 2.days >= 1
}
Instance.where(id: to_be_deleted.map { |m| m.id }).destroy_all
print "#{to_be_deleted.length} instances destroyed\n"
end
end