You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

27 lines
792 B

  1. # frozen_string_literal: true
  2. class Scheduler::UserCleanupScheduler
  3. include Sidekiq::Worker
  4. sidekiq_options lock: :until_executed, retry: 0
  5. def perform
  6. clean_unconfirmed_accounts!
  7. clean_suspended_accounts!
  8. end
  9. private
  10. def clean_unconfirmed_accounts!
  11. User.where('confirmed_at is NULL AND confirmation_sent_at <= ?', 2.days.ago).reorder(nil).find_in_batches do |batch|
  12. Account.where(id: batch.map(&:account_id)).delete_all
  13. User.where(id: batch.map(&:id)).delete_all
  14. end
  15. end
  16. def clean_suspended_accounts!
  17. AccountDeletionRequest.where('created_at <= ?', AccountDeletionRequest::DELAY_TO_DELETION.ago).reorder(nil).find_each do |deletion_request|
  18. Admin::AccountDeletionWorker.perform_async(deletion_request.account_id)
  19. end
  20. end
  21. end