https://github.com/soundcloud/simple_circuit_breaker
Simple Ruby implementation of the Circuit Breaker design pattern
https://github.com/soundcloud/simple_circuit_breaker
Last synced: 9 months ago
JSON representation
Simple Ruby implementation of the Circuit Breaker design pattern
- Host: GitHub
- URL: https://github.com/soundcloud/simple_circuit_breaker
- Owner: soundcloud
- License: mit
- Created: 2012-11-06T17:18:03.000Z (over 13 years ago)
- Default Branch: master
- Last Pushed: 2024-02-01T19:00:34.000Z (over 2 years ago)
- Last Synced: 2025-01-29T21:23:44.733Z (over 1 year ago)
- Language: Ruby
- Homepage:
- Size: 12.7 KB
- Stars: 29
- Watchers: 181
- Forks: 10
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# SimpleCircuitBreaker
## Overview
Simple Ruby implementation of the [Circuit Breaker design pattern][0].
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
```ruby
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
```bash
gem install simple_circuit_breaker
```
## Testing
[][1]
Run the tests with
```bash
rake
```
## Authors
Julius Volz (julius@soundcloud.com), Tobias Schmidt (ts@soundcloud.com).
## Alternatives
* [Circuit Breaker][2]: heavily customizable circuit handler
* [CircuitB][3]: supports keeping global circuit state in memcached
## Contributing
Pull requests welcome!
[0]: http://en.wikipedia.org/wiki/Circuit_breaker_design_pattern
[1]: http://travis-ci.org/soundcloud/simple_circuit_breaker
[2]: https://github.com/wsargent/circuit_breaker
[3]: https://github.com/alg/circuit_b