about summary refs log tree commit diff
path: root/app/lib/vacuum/backups_vacuum.rb
blob: 3b83072f369eac6fc9f7df815be41fa40265c0fe (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# frozen_string_literal: true

class Vacuum::BackupsVacuum
  def initialize(retention_period)
    @retention_period = retention_period
  end

  def perform
    vacuum_expired_backups! if retention_period?
  end

  private

  def vacuum_expired_backups!
    backups_past_retention_period.in_batches.destroy_all
  end

  def backups_past_retention_period
    Backup.unscoped.where(Backup.arel_table[:created_at].lt(@retention_period.ago))
  end

  def retention_period?
    @retention_period.present?
  end
end