2014-04-05 20:19:04 +01:00
|
|
|
class CleanApiDefenderStatisticsJob
|
2016-05-28 19:21:02 +01:00
|
|
|
include Sidekiq::Worker
|
2014-04-05 20:19:04 +01:00
|
|
|
|
2016-06-11 17:03:15 +01:00
|
|
|
sidekiq_options :queue => :low
|
|
|
|
|
2016-05-28 19:21:02 +01:00
|
|
|
def perform
|
2014-04-05 20:19:04 +01:00
|
|
|
deadline = Date.today - 1.month
|
|
|
|
Redis.current.keys.select do |key|
|
|
|
|
next if key !~ /^throttle:/
|
|
|
|
# See: https://github.com/datagraph/rack-throttle/blob/master/lib/rack/throttle/daily.rb#L41
|
|
|
|
# Formats:
|
|
|
|
# 'throttle:uname:%Y-%m-%dT%H', 'throttle:uname:%Y-%m-%d'
|
2014-04-05 20:20:44 +01:00
|
|
|
# example: "throttle:uname1:2014-01-25T20", "throttle:uname1:2014-01-25"
|
2014-04-05 20:19:04 +01:00
|
|
|
date = key.gsub(/.*:/, '').gsub(/T.*/, '')
|
|
|
|
Redis.current.del(key) if Date.parse(date) < deadline
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|