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/storage/base.rb,
lib/resilient_call/configuration.rb,
lib/resilient_call/storage/redis.rb,
lib/resilient_call/storage/memory.rb,
lib/resilient_call/circuit_breaker.rb

Defined Under Namespace

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

Constant Summary collapse

VERSION =
"0.2.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.



23
24
25
26
27
28
29
30
# File 'lib/resilient_call.rb', line 23

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

  return reject_open_circuit(circuit, options) if circuit_blocking?(circuit)

  run_with_retry(options, circuit, &block)
end

.configurationObject



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

def configuration
  @configuration ||= Configuration.new
end

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

Yields:



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

def configure
  yield configuration
end

.define_profile(name, **options) ⇒ Object



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

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

.reset_configuration!Object

Restores global defaults — useful for isolating tests.



45
46
47
# File 'lib/resilient_call.rb', line 45

def reset_configuration!
  @configuration = Configuration.new
end