Class: Sidekiq::Stats::History

Inherits:
Object
  • Object
show all
Defined in:
lib/sidekiq/api.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(days_previous, start_date = nil) ⇒ History

Returns a new instance of History.



37
38
39
40
# File 'lib/sidekiq/api.rb', line 37

def initialize(days_previous, start_date = nil)
  @days_previous = days_previous
  @start_date = start_date || Time.now.utc.to_date
end

Class Method Details

.cleanupObject



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/sidekiq/api.rb', line 50

def self.cleanup
  days_of_stats_to_keep = 180
  today = Time.now.utc.to_date
  delete_before_date = Time.now.utc.to_date - days_of_stats_to_keep

  Sidekiq.redis do |conn|
    processed_keys = conn.keys("stat:processed:*")
    earliest = "stat:processed:#{delete_before_date.to_s}"
    pkeys = processed_keys.select { |key| key < earliest }
    conn.del(pkeys) if pkeys.size > 0

    failed_keys = conn.keys("stat:failed:*")
    earliest = "stat:failed:#{delete_before_date.to_s}"
    fkeys = failed_keys.select { |key| key < earliest }
    conn.del(fkeys) if fkeys.size > 0
  end
end

Instance Method Details

#failedObject



46
47
48
# File 'lib/sidekiq/api.rb', line 46

def failed
  date_stat_hash("failed")
end

#processedObject



42
43
44
# File 'lib/sidekiq/api.rb', line 42

def processed
  date_stat_hash("processed")
end