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
768 B

  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