backups_vacuum.rb 509 B

12345678910111213141516171819202122232425
  1. # frozen_string_literal: true
  2. class Vacuum::BackupsVacuum
  3. def initialize(retention_period)
  4. @retention_period = retention_period
  5. end
  6. def perform
  7. vacuum_expired_backups! if retention_period?
  8. end
  9. private
  10. def vacuum_expired_backups!
  11. backups_past_retention_period.in_batches.destroy_all
  12. end
  13. def backups_past_retention_period
  14. Backup.unscoped.where(Backup.arel_table[:created_at].lt(@retention_period.ago))
  15. end
  16. def retention_period?
  17. @retention_period.present?
  18. end
  19. end