scheduler to delete old accounts
This commit is contained in:
parent
a3b8fa244a
commit
d8962d2468
2 changed files with 44 additions and 0 deletions
40
app/workers/scheduler/old_account_cleanup_scheduler.rb
Normal file
40
app/workers/scheduler/old_account_cleanup_scheduler.rb
Normal file
|
@ -0,0 +1,40 @@
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
class Scheduler::OldAccountCleanupScheduler
|
||||||
|
include Sidekiq::Worker
|
||||||
|
|
||||||
|
# Each processed deletion request may enqueue an enormous
|
||||||
|
# amount of jobs in the `pull` queue, so only enqueue when
|
||||||
|
# the queue is empty or close to being so.
|
||||||
|
MAX_PULL_SIZE = 50
|
||||||
|
|
||||||
|
# Since account deletion is very expensive, we want to avoid
|
||||||
|
# overloading the server by queing too much at once.
|
||||||
|
MAX_DELETIONS_PER_JOB = 5
|
||||||
|
|
||||||
|
sidekiq_options retry: 0
|
||||||
|
|
||||||
|
def perform
|
||||||
|
return if Sidekiq::Queue.new('pull').size > MAX_PULL_SIZE
|
||||||
|
|
||||||
|
clean_old_accounts!
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def clean_old_accounts!
|
||||||
|
Account
|
||||||
|
# only fetch local accounts
|
||||||
|
.where("domain IS NULL")
|
||||||
|
# id -99 is the instance actor
|
||||||
|
.where("id <> -99")
|
||||||
|
# don't delete admin
|
||||||
|
.where("username <> 'admin'")
|
||||||
|
.where("created_at < ?", 1.day.ago)
|
||||||
|
.order(created_at: :asc)
|
||||||
|
.limit(MAX_DELETIONS_PER_JOB)
|
||||||
|
.each do |account|
|
||||||
|
AccountDeletionWorker.perform_async(account.id, { :reserve_username => false })
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -58,3 +58,7 @@
|
||||||
interval: 1 minute
|
interval: 1 minute
|
||||||
class: Scheduler::SuspendedUserCleanupScheduler
|
class: Scheduler::SuspendedUserCleanupScheduler
|
||||||
queue: scheduler
|
queue: scheduler
|
||||||
|
old_account_cleanup_scheduler:
|
||||||
|
interval: 1 minute
|
||||||
|
class: Scheduler::OldAccountCleanupScheduler
|
||||||
|
queue: scheduler
|
||||||
|
|
Loading…
Add table
Reference in a new issue