Module: ResilientCall

Defined in:
lib/resilient_call.rb,
lib/resilient_call/mixin.rb,
lib/resilient_call/errors.rb,
lib/resilient_call/circuit.rb,
lib/resilient_call/retrier.rb,
lib/resilient_call/version.rb,
lib/resilient_call/configuration.rb,
lib/resilient_call/circuit_breaker.rb

Defined Under Namespace

Modules: CircuitBreaker, Mixin Classes: Circuit, CircuitOpenError, Configuration, Retrier, RetriesExhaustedError

Constant Summary collapse

VERSION =
"0.1.0"

Class Method Summary collapse

Class Method Details

.call(**options, &block) ⇒ Object

Runs ‘block` with retry and, when `circuit:` is given, circuit-breaker protection. Option precedence: inline > profile > global config > defaults.



15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/resilient_call.rb', line 15

def call(**options, &block)
  options = resolve_options(options)
  circuit = circuit_for(options)

  if circuit && !circuit.allow_request?
    return options[:fallback].call if options[:fallback]

    raise circuit_open_error(circuit, options)
  end

  run_with_retry(options, circuit, &block)
end

.configurationObject



32
33
34
# File 'lib/resilient_call.rb', line 32

def configuration
  @configuration ||= Configuration.new
end

.configure {|configuration| ... } ⇒ Object

Yields:



28
29
30
# File 'lib/resilient_call.rb', line 28

def configure
  yield configuration
end

.define_profile(name, **options) ⇒ Object



36
37
38
# File 'lib/resilient_call.rb', line 36

def define_profile(name, **options)
  configuration.profiles[name] = options
end

.reset_configuration!Object

Restores global defaults — useful for isolating tests.



41
42
43
# File 'lib/resilient_call.rb', line 41

def reset_configuration!
  @configuration = Configuration.new
end