feat: clean up old instances automatically
This commit is contained in:
parent
5aa5fe0f5a
commit
070ffa8eeb
8 changed files with 85 additions and 42 deletions
13
app/jobs/instance_cleanup_job.rb
Normal file
13
app/jobs/instance_cleanup_job.rb
Normal 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
|
Loading…
Add table
Add a link
Reference in a new issue