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
-
.call(**options, &block) ⇒ Object
Runs ‘block` with retry and, when `circuit:` is given, circuit-breaker protection.
- .configuration ⇒ Object
- .configure {|configuration| ... } ⇒ Object
- .define_profile(name, **options) ⇒ Object
-
.reset_configuration! ⇒ Object
Restores global defaults — useful for isolating tests.
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(**, &block) = () circuit = circuit_for() if circuit && !circuit.allow_request? return [:fallback].call if [:fallback] raise circuit_open_error(circuit, ) end run_with_retry(, circuit, &block) end |
.configuration ⇒ Object
32 33 34 |
# File 'lib/resilient_call.rb', line 32 def configuration @configuration ||= Configuration.new end |
.configure {|configuration| ... } ⇒ Object
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, **) configuration.profiles[name] = 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 |