Module: Sidekiq::QueueThrottled::RedisKeyManager

Included in:
JobThrottler
Defined in:
lib/sidekiq/queue_throttled/job_throttler.rb

Instance Method Summary collapse

Instance Method Details

#concurrency_key(key_suffix) ⇒ Object



6
7
8
# File 'lib/sidekiq/queue_throttled/job_throttler.rb', line 6

def concurrency_key(key_suffix)
  "#{Sidekiq::QueueThrottled.configuration.redis_key_prefix}:concurrency:#{@job_class}:#{key_suffix}"
end

#rate_key(key_suffix, period) ⇒ Object



10
11
12
13
# File 'lib/sidekiq/queue_throttled/job_throttler.rb', line 10

def rate_key(key_suffix, period)
  window = Time.now.to_i / period
  "#{Sidekiq::QueueThrottled.configuration.redis_key_prefix}:rate:#{@job_class}:#{key_suffix}:#{window}"
end

#resolve_key_suffix(key_suffix, args) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/sidekiq/queue_throttled/job_throttler.rb', line 15

def resolve_key_suffix(key_suffix, args)
  case key_suffix
  when Proc
    key_suffix.call(*args)
  when Symbol
    args.first.send(key_suffix) if args.first.respond_to?(key_suffix)
  when String
    key_suffix
  else
    'default'
  end.to_s
end