Simple Ruby implementation of the Circuit Breaker design pattern
Ruby
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
lib
test
.travis.yml
LICENSE
README.md
Rakefile
simple_circuit_breaker.gemspec

README.md

SimpleCircuitBreaker

Overview

Simple Ruby implementation of the Circuit Breaker design pattern.

This implementation aims to be as simple as possible. It does not have external dependencies and only handles the core circuit breaker functionality. Wrapping backend calls in timeouts and other exception handling is left to the user of the library.

Usage

failure_threshold = 3 # Trip the circuit after 3 consecutive failures.
retry_timeout = 10    # Retry on an open circuit after 10 seconds.
circuit_breaker = SimpleCircuitBreaker.new(failure_threshold, retry_timeout)

# By default, all exceptions will trip the circuit.
circuit_breaker.handle do
  FooClient.new.request
end

# Setting explicit exceptions that trip the circuit:
circuit_breaker.handle FooError, BarError do
  FooClient.new.request
end

SimpleCircuitBreaker#handle raises a SimpleCircuitBreaker::CircuitOpenError when the circuit is open. Otherwise, it re-raises any exceptions that occur in the block.

Installation

gem install simple_circuit_breaker

Testing

Build Status

Run the tests with

rake

Authors

Julius Volz (julius@soundcloud.com), Tobias Schmidt (ts@soundcloud.com).

Alternatives

  • Circuit Breaker: heavily customizable circuit handler
  • CircuitB: supports keeping global circuit state in memcached

Contributing

Pull requests welcome!