lib/logstash/circuit_breaker.rb in logstash-input-lumberjack-1.0.3 vs lib/logstash/circuit_breaker.rb in logstash-input-lumberjack-1.0.4
- old
+ new
@@ -2,12 +2,16 @@
require "cabin"
module LogStash
# Largely inspired by Martin's fowler circuit breaker
class CircuitBreaker
+ # Raised when too many errors has occured and we refuse to execute the block
class OpenBreaker < StandardError; end
+ # Raised when we catch an error that we count
+ class HalfOpenBreaker < StandardError; end
+
# Error threshold before opening the breaker,
# if the breaker is open it wont execute the code.
DEFAULT_ERROR_THRESHOLD = 5
# Recover time after the breaker is open to start
@@ -46,9 +50,11 @@
end
end
rescue *@exceptions => e
logger.warn("CircuitBreaker::rescuing exceptions", :name => @name, :exception => e.class)
increment_errors(e)
+
+ raise HalfOpenBreaker
end
def closed?
state == :close || state == :half_open
end