Skip to content

Simple Ruby implementation of the Circuit Breaker design pattern

License

Notifications You must be signed in to change notification settings

soundcloud/simple_circuit_breaker

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

21 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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 ([email protected]), Tobias Schmidt ([email protected]).

Alternatives

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

Contributing

Pull requests welcome!

About

Simple Ruby implementation of the Circuit Breaker design pattern

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages