Class: Debci::Expiration

Inherits:
Object
  • Object
show all
Defined in:
lib/debci/expiration.rb

Defined Under Namespace

Classes: CLI

Instance Method Summary collapse

Instance Method Details

#runObject



17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/debci/expiration.rb', line 17

def run
  expire_date = Time.now - Debci.config.data_retention.days
  start_date = timestamp.stat.mtime

  jobs = Debci::Job.where(['date >= ? AND date <= ?', start_date, expire_date])
  jobs.in_batches.each do |subset|
    subset.each do |job|
      job.cleanup(reason: "past data retention period")
    end
  end

  FileUtils.touch(timestamp, mtime: expire_date)
end

#timestampObject



8
9
10
11
12
13
14
15
# File 'lib/debci/expiration.rb', line 8

def timestamp
  @timestamp ||= (Pathname(Debci.config.data_basedir) / 'expire.stamp').tap do |t|
    unless t.exist?
      oldest = Debci::Job.minimum(:date)
      FileUtils.touch(t, mtime: oldest)
    end
  end
end