class PuppetHerald::PurgeCronJob

A cron job for Herald

Constants

SECONDS_IN_DAY

Number of seconds in a day

@return [Integer]

Public Instance Methods

parse_limit(limit) click to toggle source

Parse a limit and returns number of seconds

@param limit [String] a limit as string @return [DateTime] a date in the past - now minus limit

# File lib/puppet-herald/purgecronjob.rb, line 28
def parse_limit(limit)
  require 'rufus/scheduler'
  seconds = Rufus::Scheduler.parse limit
  now = DateTime.now
  now - Rational(seconds, SECONDS_IN_DAY)
end
run!() click to toggle source

Run a purge job

@return [nil]

# File lib/puppet-herald/purgecronjob.rb, line 13
def run!
  require 'puppet-herald'
  require 'puppet-herald/models/report'
  limit = ENV['PUPPET_HERALD_PURGE_LIMIT'] || '90d'
  date = parse_limit limit
  PuppetHerald.logger.info "Running a purge reports job with limit: `#{limit}` that is `#{date}`..."
  reports = PuppetHerald::Models::Report.purge_older_then(date)
  PuppetHerald.logger.info "Job completed. Purged: #{reports} reports."
  nil
end