Module: Faulty::Patch::Base
- Included in:
- Elasticsearch, Mysql2, Redis, Redis::Middleware
- Defined in:
- lib/faulty/patch/base.rb
Overview
Can be included in patch modules to provide common functionality
The patch needs to set @faulty_circuit
Instance Method Summary collapse
-
#faulty_run { ... } ⇒ Object
Run a block wrapped by
@faulty_circuit
.
Instance Method Details
#faulty_run { ... } ⇒ Object
Run a block wrapped by @faulty_circuit
If @faulty_circuit
is not set, the block will be run with no
circuit.
Nested calls to this method will only cause the circuit to be triggered once.
34 35 36 37 38 39 40 41 42 43 |
# File 'lib/faulty/patch/base.rb', line 34 def faulty_run(&block) faulty_running_key = "faulty_running_#{object_id}" return yield unless @faulty_circuit return yield if Thread.current[faulty_running_key] Thread.current[faulty_running_key] = true @faulty_circuit.run(&block) ensure Thread.current[faulty_running_key] = nil end |