require 'sidekiq/circuit_breaker/configuration' module Sidekiq module CircuitBreaker module Worker def self.included(base) base.extend(ClassMethods) end def sidekiq_circuit_breaker_manager(args) options = self.class.sidekiq_circuit_breaker_options scope = scope(args) CircuitBreaker::Manager.new(scope, options) end private def scope(args) options = self.class.sidekiq_circuit_breaker_options extract_scope(options, args) || self.class.name end def extract_scope(options, args) scope = options.scope return scope if scope.is_a?(String) return unless scope.respond_to?(:call) options.scope.call(*args) end module ClassMethods def sidekiq_circuit_breaker_enabled? true end def sidekiq_circuit_breaker yield(sidekiq_circuit_breaker_options) if block_given? end def sidekiq_circuit_breaker_options @@setup ||= Sidekiq::CircuitBreaker::Configuration.new end end end end end