class Resque::Pool::ConfigLoaders::Throttled
Throttle the frequency of loading pool configuration Defaults to call only once per 10 seconds.
Public Class Methods
new(config_loader, period: 10, time_source: Time)
click to toggle source
Calls superclass method
# 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
Public Instance Methods
call(env)
click to toggle source
Calls superclass method
# 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!()
click to toggle source
Calls superclass method
# File lib/resque/pool/config_loaders/throttled.rb, line 30 def reset! @last_check = 0 super if @resettable end
Private Instance Methods
now()
click to toggle source
# File lib/resque/pool/config_loaders/throttled.rb, line 37 def now @time_source.now.to_f end