class Sidekiq::CircuitBreaker::Middleware::Client

Public Instance Methods

call(worker_class, msg, queue, redis_pool) { || ... } click to toggle source
# File lib/sidekiq/circuit_breaker/middleware/client.rb, line 11
def call(worker_class, msg, queue, redis_pool)
  begin
    worker = constantize(worker_class)
  rescue NameError
    return yield
  end

  circuit_breaker = worker.respond_to?(:sidekiq_circuit_breaker_enabled?)
  return yield unless circuit_breaker

  options = worker.sidekiq_circuit_breaker_options
  scope = extract_scope(worker_class, msg, options)

  mgr = CircuitBreaker::Manager.new(scope, options)
  if mgr.open? && msg['at'].nil?
    msg['at'] = (Time.now + (mgr.time_to_close  + additional_seconds)).to_f
  end

  yield
end

Private Instance Methods

additional_seconds() click to toggle source
# File lib/sidekiq/circuit_breaker/middleware/client.rb, line 34
def additional_seconds
  rand(3..10)
end
constantize(str) click to toggle source
# File lib/sidekiq/circuit_breaker/middleware/client.rb, line 40
def constantize(str)
  names = str.split('::')
  names.shift if names.empty? || names.first.empty?

  names.inject(Object) do |constant, name|
    constant.const_defined?(name, false) ? constant.const_get(name, false) : constant.const_missing(name)
  end
end