Class: Circuitbox

Inherits:
Object
  • Object
show all
Extended by:
Configuration
Defined in:
lib/circuitbox.rb,
lib/circuitbox/version.rb,
lib/circuitbox/errors/error.rb,
lib/circuitbox/memory_store.rb,
lib/circuitbox/configuration.rb,
lib/circuitbox/notifier/null.rb,
lib/circuitbox/circuit_breaker.rb,
lib/circuitbox/excon_middleware.rb,
lib/circuitbox/time_helper/real.rb,
lib/circuitbox/faraday_middleware.rb,
lib/circuitbox/time_helper/monotonic.rb,
lib/circuitbox/memory_store/container.rb,
lib/circuitbox/notifier/active_support.rb,
lib/circuitbox/errors/open_circuit_error.rb,
lib/circuitbox/errors/service_failure_error.rb

Defined Under Namespace

Modules: Configuration, Notifier, TimeHelper Classes: CircuitBreaker, Error, ExconMiddleware, FaradayMiddleware, MemoryStore, OpenCircuitError, ServiceFailureError

Constant Summary collapse

VERSION =
'2.0.0'

Instance Attribute Summary

Attributes included from Configuration

#default_circuit_store, #default_notifier

Class Method Summary collapse

Methods included from Configuration

configure, extended

Class Method Details

.circuit(service_name, options = {}) ⇒ Circuitbox::CircuitBreaker .circuit(service_name, options = {}, &block) ⇒ Object?

Overloads:

  • .circuit(service_name, options = {}) ⇒ Circuitbox::CircuitBreaker

    Returns a Circuitbox::CircuitBreaker for the given service_name

    Parameters:

    • service_name (String, Symbol)

      Name of the service Mixing Symbols/Strings for the same service (:test/‘test’) will result in multiple circuits being created that point to the same service.

    • options (Hash) (defaults to: {})

      Options for the circuit (See Circuitbox::CircuitBreaker#initialize options) Any configuration options should always be passed when calling this method.

    Returns:

  • .circuit(service_name, options = {}, &block) ⇒ Object?

    Runs the circuit with the given block The circuit’s run method is called with ‘exception` set to false

    Parameters:

    • service_name (String, Symbol)

      Name of the service Mixing Symbols/Strings for the same service (:test/‘test’) will result in multiple circuits being created that point to the same service.

    • options (Hash) (defaults to: {})

      Options for the circuit (See Circuitbox::CircuitBreaker#initialize options) Any configuration options should always be passed when calling this method.

    Returns:

    • (Object)

      The result of the block

    • (nil)

      If the circuit is open



36
37
38
39
40
41
42
# File 'lib/circuitbox.rb', line 36

def circuit(service_name, options, &block)
  circuit = find_or_create_circuit_breaker(service_name, options)

  return circuit unless block

  circuit.run(exception: false, &block)
end