Method: Faulty::Circuit#run
- Defined in:
- lib/faulty/circuit.rb
#run(cache: nil) { ... } ⇒ Object
Run a block protected by this circuit
If the circuit is closed, the block will run. Any exceptions raised inside the block will be checked against the error and exclude options to determine whether that error should be captured. If the error is captured, this run will be recorded as a failure.
If the circuit exceeds the failure conditions, this circuit will be tripped and marked as open. Any future calls to run will not execute the block, but instead wait for the cool down period. Once the cool down period passes, the circuit transitions to half-open, and the block will be allowed to run.
If the circuit fails again while half-open, the circuit will be closed for a second cool down period. However, if the circuit completes successfully, the circuit will be closed and reset to its initial state.
When this is run, the given options are persisted to the storage backend.
304 305 306 307 308 309 310 311 312 313 314 |
# File 'lib/faulty/circuit.rb', line 304 def run(cache: nil, &block) cached_value = cache_read(cache) # return cached unless cached.nil? return cached_value if !cached_value.nil? && !cache_should_refresh?(cache) current_status = status return run_skipped(cached_value) unless current_status.can_run? run_exec(current_status, cached_value, cache, &block) end |