Class: Wurk::Limiter::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/wurk/limiter.rb

Overview

Global config. Sidekiq Enterprise documents three knobs (§1.6): ‘backoff` (Proc), `redis` (a Hash that builds a dedicated pool), and `errors` (Array of exception classes the middleware also treats as OverLimit). All three are mutable and re-read on every push/perform.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfig

Returns a new instance of Config.



66
67
68
69
70
71
# File 'lib/wurk/limiter.rb', line 66

def initialize
  @backoff = DEFAULT_BACKOFF
  @errors = [OverLimit]
  @redis = nil
  @redis_pool = nil
end

Instance Attribute Details

#backoffObject

Returns the value of attribute backoff.



63
64
65
# File 'lib/wurk/limiter.rb', line 63

def backoff
  @backoff
end

#errorsObject

Returns the value of attribute errors.



63
64
65
# File 'lib/wurk/limiter.rb', line 63

def errors
  @errors
end

#redisObject

Returns the value of attribute redis.



64
65
66
# File 'lib/wurk/limiter.rb', line 64

def redis
  @redis
end

Instance Method Details

#poolObject



82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/wurk/limiter.rb', line 82

def pool
  return nil if @redis.nil?

  @pool ||= case @redis
            when Wurk::RedisPool then @redis
            when Hash
              Wurk::RedisPool.new(
                size: @redis[:size] || 10,
                url: @redis[:url] || Wurk::RedisPool::DEFAULT_URL,
                timeout: @redis[:timeout] || Wurk::RedisPool::DEFAULT_TIMEOUT,
                name: 'limiter'
              )
            else
              raise ArgumentError, "Limiter.config.redis must be Hash or RedisPool, got #{@redis.class}"
            end
end