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.



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

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



65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/sidekiq/api.rb', line 65

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



61
62
63
# File 'lib/sidekiq/api.rb', line 61

def failed
  date_stat_hash("failed")
end

#processedObject



57
58
59
# File 'lib/sidekiq/api.rb', line 57

def processed
  date_stat_hash("processed")
end