lib/resque/plugins/restriction.rb in resque-restriction-0.6.0 vs lib/resque/plugins/restriction.rb in resque-restriction-0.7.0
- old
+ new
@@ -1,9 +1,10 @@
module Resque
module Plugins
module Restriction
SECONDS = {
+ :per_second => 1,
:per_minute => 60,
:per_hour => 60*60,
:per_day => 24*60*60,
:per_week => 7*24*60*60,
:per_month => 31*24*60*60,
@@ -65,10 +66,10 @@
def redis_key(period, *args)
period_key, custom_key = period.to_s.split('_and_')
period_str = case period_key.to_sym
when :concurrent then "*"
- when :per_minute, :per_hour, :per_day, :per_week then (Time.now.to_i / SECONDS[period_key.to_sym]).to_s
+ when :per_second, :per_minute, :per_hour, :per_day, :per_week then (Time.now.to_i / SECONDS[period_key.to_sym]).to_s
when :per_month then Date.today.strftime("%Y-%m")
when :per_year then Date.today.year.to_s
else period_key =~ /^per_(\d+)$/ and (Time.now.to_i / $1.to_i).to_s end
custom_value = (custom_key && args.first && args.first.is_a?(Hash)) ? args.first[custom_key] : nil
[RESTRICTION_QUEUE_PREFIX, self.restriction_identifier(*args), custom_value, period_str].compact.join(":")