{"id":25824430,"url":"https://github.com/petitviolet/rcb","last_synced_at":"2025-02-28T12:51:10.021Z","repository":{"id":56891153,"uuid":"242353918","full_name":"petitviolet/rcb","owner":"petitviolet","description":"Circuit Breaker for Ruby","archived":false,"fork":false,"pushed_at":"2020-04-30T13:26:56.000Z","size":38,"stargazers_count":2,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-01-20T09:19:08.574Z","etag":null,"topics":["circuit-breaker","ruby","rubygem"],"latest_commit_sha":null,"homepage":"","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/petitviolet.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-02-22T14:19:37.000Z","updated_at":"2021-11-08T10:34:07.000Z","dependencies_parsed_at":"2022-08-21T00:20:54.391Z","dependency_job_id":null,"html_url":"https://github.com/petitviolet/rcb","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/petitviolet%2Frcb","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/petitviolet%2Frcb/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/petitviolet%2Frcb/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/petitviolet%2Frcb/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/petitviolet","download_url":"https://codeload.github.com/petitviolet/rcb/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239879307,"owners_count":19712176,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["circuit-breaker","ruby","rubygem"],"created_at":"2025-02-28T12:51:09.355Z","updated_at":"2025-02-28T12:51:10.008Z","avatar_url":"https://github.com/petitviolet.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Rcb - Ruby Circuit Breaker\n\n[![rcb](https://badge.fury.io/rb/rcb.svg)](https://badge.fury.io/rb/rcb)\n[![Actions Status](https://github.com/petitviolet/rcb/workflows/test/badge.svg)](https://github.com/petitviolet/rcb/actions)\n\n[Circuit Breaker](https://martinfowler.com/bliki/CircuitBreaker.html) implementation for/by Ruby.  \nCircuitBreaker is a great pattern to build robust system consists of bunch of microservices.\n\n- Close\n    - An operational state\n- Open\n    - A not operational state\n- Half Open\n    - On the way of it's state to Close from Open.\n\n## Installation\n\nAdd this line to your application's Gemfile:\n\n```ruby\ngem 'rcb'\n```\n\nAnd then execute:\n\n    $ bundle install\n\nOr install it yourself as:\n\n    $ gem install rcb\n\n## Usage\n\n### Import\n\nTo use rcb, insert this line:\n\n```ruby\nrequire 'rcb'\n```\n\n### Configuration\n\nAdd configuration with specifying `tag` like:\n\n```ruby\nRcb.configure('fooo.com') do |config|\n    config.open_condition.max_failure_count 1\n    config.open_condition.window_msec 1000\n    config.reset_timeout_msec 100\nend\n\nRcb.configure('hoge.com') do |config|\n    config.open_condition.max_failure_count 3\n    config.open_condition.window_msec 3000\n    config.reset_timeout_msec 300\nend\n```\n\nThese configurations are for both 'fooo.com' and 'hoge.com'.\n\n- `open_condition`: a condition to decide whether trip to open from close\n    - `max_failure_count`: a threshold for execution failures. \n        - if the breaker reaches the given `max_failure_count`, enters Open state from Close \n    - `window_msec`: a window time(milliseconds) for failures\n        - if the breaker catched failures more than `window_msec` before, they are discarded\n- `reset_timeout_msec`: milliseconds to wait for next try\n    - after the given `reset_timeout_msec`, the circuit breaker enters a Half-Open state from Open\n\n### Apply circuit breaker to executions\n\nPass a block to a method `Rcb::Instance#run!` to apply circuit-breaker to a execution.\n\n```ruby\nRcb.for('example.com').run! do # pass a block\n    if rand(2) == 0\n        raise 'fail!'\n    else\n        true\n    end\nend\n```\n\nYou can see more example in [tests](./test).\n\n## Development\n\nAfter checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.\n\nTo install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).\n\n## Contributing\n\nBug reports and pull requests are welcome on GitHub at https://github.com/petitviolet/rcb. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/petitviolet/rcb/blob/master/CODE_OF_CONDUCT.md).\n\n\n## License\n\nThe gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).\n\n## Code of Conduct\n\nEveryone interacting in the Rcb project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/petitviolet/rcb/blob/master/CODE_OF_CONDUCT.md).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpetitviolet%2Frcb","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpetitviolet%2Frcb","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpetitviolet%2Frcb/lists"}