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.



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

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



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/sidekiq/api.rb', line 58

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



54
55
56
# File 'lib/sidekiq/api.rb', line 54

def failed
  date_stat_hash("failed")
end

#processedObject



50
51
52
# File 'lib/sidekiq/api.rb', line 50

def processed
  date_stat_hash("processed")
end