Class: Tally::Sweeper

Inherits:
Object
  • Object
show all
Defined in:
lib/tally/sweeper.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(key: nil, day: "*", record: nil, type: nil) ⇒ Sweeper

Returns a new instance of Sweeper.



4
5
6
7
8
9
# 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

Class Method Details

.sweep!(**args) ⇒ Object



35
36
37
# File 'lib/tally/sweeper.rb', line 35

def self.sweep!(**args)
  new(**args).sweep!
end

Instance Method Details

#purge_dateObject



11
12
13
# File 'lib/tally/sweeper.rb', line 11

def purge_date
  @purge_date ||= 3.days.ago.beginning_of_day.to_date
end

#purgeable_keysObject



15
16
17
18
19
20
21
# 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!Object



23
24
25
26
27
28
29
30
31
32
33
# File 'lib/tally/sweeper.rb', line 23

def sweep!
  Tally.redis do |conn|
    purgeable_keys.in_groups_of(25, fill_with = false).each do |group|
      conn.pipelined do |pipeline|
        group.each do |key|
          pipeline.del(key)
        end
      end
    end
  end
end