No commit activity in last 3 years
No release in over 3 years
Self-resetting breaker retries the protected call after a suitable interval, and it also resets when the call succeeds.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
 Dependencies

Runtime

>= 10
>= 3
 Project Readme

Circuit Breaker

Gem Version Gem Downloads build

A circuit breaker which terminates the connection or block of code from executing when it reaches the timeout. It helps in preventing blocking requests from slowing down your server.

How it works

Refer the following diagram:

CircuitBreaker

Getting started

Add following line to your Gemfile:

gem 'circuit_breaker-ruby', '~> 0.1.3'

Usage

circuit_breaker = CircuitBreaker::Shield.new(
  invocation_timeout: 1,
  failure_threshold: 2,
  failure_threshold_percentage: 0.2,
  retry_timeout: 10
)
circuit_breaker.protect { sleep(10) }

Running tests

bundle exec rake

Configuration

Add the following configuration to config/initializers/circuit_breaker.rb. These are the default values.

CircuitBreaker.configure do |cb|
  cb.failure_threshold = 10
  cb.failure_threshold_percentage = 0.5
  cb.invocation_timeout = 10
  cb.retry_timeout = 60
end

Contributing

If you have any issues with circuit_breaker-ruby, or feature requests, please add an issue on GitHub or fork the project and send a pull request. Please include passing specs with all pull requests.

Copyright and License

Copyright (c) 2019, Scripbox.

circuit_breaker-ruby source code is licensed under the MIT License.

References

CircuitBreaker - Martin Fowler