Sha256: d2c5f85174c04b81b8205ff6cc5770dd21f11d4071a3d4245a8414abf1339945

Contents?: true

Size: 1.09 KB

Versions: 1

Compression:

Stored size: 1.09 KB

Contents

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

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
sidekiq-circuit-breaker-0.1.4 lib/sidekiq/circuit_breaker/worker.rb