Class: Resque::Pool::ConfigLoaders::Throttled

Inherits:
SimpleDelegator
  • Object
show all
Defined in:
lib/resque/pool/config_loaders/throttled.rb

Overview

Throttle the frequency of loading pool configuration Defaults to call only once per 10 seconds.

Instance Method Summary collapse

Constructor Details

#initialize(config_loader, period: 10, time_source: Time) ⇒ Throttled

Returns a new instance of Throttled.



12
13
14
15
16
17
18
# File 'lib/resque/pool/config_loaders/throttled.rb', line 12

def initialize(config_loader, period: 10, time_source: Time)
  super(config_loader)
  @period = period
  @resettable = config_loader.respond_to?(:reset!)
  @last_check = 0
  @time_source = time_source
end

Instance Method Details

#call(env) ⇒ Object



20
21
22
23
24
25
26
27
28
# File 'lib/resque/pool/config_loaders/throttled.rb', line 20

def call(env)
  # We do not need to cache per `env`, since the value of `env` will not
  # change during the life of the process.
  if (now > @last_check + @period)
    @cache = super
    @last_check = now
  end
  @cache
end

#reset!Object



30
31
32
33
# File 'lib/resque/pool/config_loaders/throttled.rb', line 30

def reset!
  @last_check = 0
  super if @resettable
end