Class: SimpleCircuit
- Inherits:
-
Object
- Object
- SimpleCircuit
- Defined in:
- lib/simple_circuit.rb
Constant Summary collapse
- VERSION =
"0.1.0"
Instance Method Summary collapse
- #closed? ⇒ Boolean
-
#initialize(payload:, max_failures: 100, retry_in: 60, logger: nil) ⇒ SimpleCircuit
constructor
A new instance of SimpleCircuit.
- #open? ⇒ Boolean
- #pass(message, *args) ⇒ Object
Constructor Details
#initialize(payload:, max_failures: 100, retry_in: 60, logger: nil) ⇒ SimpleCircuit
Returns a new instance of SimpleCircuit.
4 5 6 7 8 9 10 11 12 13 |
# File 'lib/simple_circuit.rb', line 4 def initialize(payload:, max_failures: 100, retry_in: 60, logger: nil) @payload = payload @max_failures = max_failures @retry_in = retry_in @logger = logger @mutex = Mutex.new close end |
Instance Method Details
#closed? ⇒ Boolean
32 33 34 |
# File 'lib/simple_circuit.rb', line 32 def closed? @closed end |
#open? ⇒ Boolean
28 29 30 |
# File 'lib/simple_circuit.rb', line 28 def open? !closed? end |
#pass(message, *args) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/simple_circuit.rb', line 15 def pass(, *args) fail @e if open? && !time_to_retry? result = payload.public_send(, *args) close if open? result rescue => e raise e if open? @e = e @mutex.synchronize{ @failures[e.class] += 1 } break! if @failures[e.class] > max_failures raise e end |