class Tally::Sweeper

Public Class Methods

new(key: nil, day: "*", record: nil, type: nil) click to toggle source
# File lib/tally/sweeper.rb, line 4
def initialize(key: nil, day: "*", record: nil, type: nil)
  @key = key
  @day = day
  @record = record
  @type = type
end
sweep!(*args) click to toggle source
# File lib/tally/sweeper.rb, line 35
def self.sweep!(*args)
  new(*args).sweep!
end

Public Instance Methods

purge_date() click to toggle source
# File lib/tally/sweeper.rb, line 11
def purge_date
  @purge_date ||= 3.days.ago.beginning_of_day.to_date
end
purgeable_keys() click to toggle source
# File lib/tally/sweeper.rb, line 15
def purgeable_keys
  @purgeable_keys ||= finder.entries.map do |entry|
    if entry.date <= purge_date
      entry.raw_key
    end
  end.compact
end
sweep!() click to toggle source
# File lib/tally/sweeper.rb, line 23
def sweep!
  Tally.redis do |conn|
    purgeable_keys.in_groups_of(25, fill_with = nil).each do |group|
      conn.pipelined do
        group.each do |key|
          conn.del(key)
        end
      end
    end
  end
end

Private Instance Methods

finder() click to toggle source
# File lib/tally/sweeper.rb, line 41
def finder
  @key_finder ||= KeyFinder.new(key: @key, day: @day, record: @record, type: @type)
end