Sha256: e2d5f3a6d3a5198a347a298051752bb00d11365be69995f3dbdb97735c3852ac

Contents?: true

Size: 983 Bytes

Versions: 1

Compression:

Stored size: 983 Bytes

Contents

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


Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
sidekiq-circuit-breaker-0.1.5 lib/sidekiq/circuit_breaker/middleware/server.rb