require 'sidekiq/circuit_breaker/scope' module Sidekiq module CircuitBreaker module Middleware class Server include Sidekiq::CircuitBreaker::Scope def call(worker, msg, queue) circuit_breaker_enabled = worker.class.respond_to?(:sidekiq_circuit_breaker_enabled?) return yield unless circuit_breaker_enabled options = worker.class.sidekiq_circuit_breaker_options scope = extract_scope(worker.class.name, msg, options) manager = Manager.new(scope, options) resquedule_job(worker, msg) and return if manager.open? begin yield rescue => e manager.evaluate_failure raise e end manager.register_success end def resquedule_job(worker, msg) Sidekiq::Client.push( 'class' => worker.class.name, 'args' => msg['args'] ) end end end end end