ip_cleanup_scheduler.rb 768 B

123456789101112131415161718192021222324252627
  1. # frozen_string_literal: true
  2. class Scheduler::IpCleanupScheduler
  3. include Sidekiq::Worker
  4. IP_RETENTION_PERIOD = 1.year.freeze
  5. sidekiq_options retry: 0
  6. def perform
  7. clean_ip_columns!
  8. clean_expired_ip_blocks!
  9. end
  10. private
  11. def clean_ip_columns!
  12. SessionActivation.where('updated_at < ?', IP_RETENTION_PERIOD.ago).in_batches.destroy_all
  13. User.where('current_sign_in_at < ?', IP_RETENTION_PERIOD.ago).in_batches.update_all(sign_up_ip: nil)
  14. LoginActivity.where('created_at < ?', IP_RETENTION_PERIOD.ago).in_batches.destroy_all
  15. Doorkeeper::AccessToken.where('last_used_at < ?', IP_RETENTION_PERIOD.ago).in_batches.update_all(last_used_ip: nil)
  16. end
  17. def clean_expired_ip_blocks!
  18. IpBlock.expired.in_batches.destroy_all
  19. end
  20. end