{"id":19723515,"url":"https://github.com/remind101/all_my_circuits","last_synced_at":"2026-03-04T23:31:09.086Z","repository":{"id":32521662,"uuid":"36102946","full_name":"remind101/all_my_circuits","owner":"remind101","description":"Mostly threadsafe implementation of the CircuitBreaker pattern for Ruby.","archived":false,"fork":false,"pushed_at":"2017-04-12T18:28:01.000Z","size":95,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":80,"default_branch":"master","last_synced_at":"2025-12-28T16:57:55.136Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-2-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/remind101.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-05-23T01:45:44.000Z","updated_at":"2017-02-28T21:19:08.000Z","dependencies_parsed_at":"2022-06-26T23:09:59.176Z","dependency_job_id":null,"html_url":"https://github.com/remind101/all_my_circuits","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/remind101/all_my_circuits","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/remind101%2Fall_my_circuits","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/remind101%2Fall_my_circuits/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/remind101%2Fall_my_circuits/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/remind101%2Fall_my_circuits/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/remind101","download_url":"https://codeload.github.com/remind101/all_my_circuits/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/remind101%2Fall_my_circuits/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30099337,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-04T22:49:54.894Z","status":"ssl_error","status_checked_at":"2026-03-04T22:49:48.883Z","response_time":59,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":[],"created_at":"2024-11-11T23:22:28.632Z","updated_at":"2026-03-04T23:31:08.696Z","avatar_url":"https://github.com/remind101.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# AllMyCircuits\n\n[![Circle CI](https://circleci.com/gh/remind101/all_my_circuits.svg?style=svg\u0026circle-token=3c0f7294a61e095f789f369f96bdd266ddd80258)](https://circleci.com/gh/remind101/all_my_circuits)\n\n![funny image goes here](https://raw.githubusercontent.com/remind101/all_my_circuits/master/all_my_circuits.jpg?token=AAc0YcX8xOhT0o4_Ko-IxKEEQk2PTUJYks5VaR0ywA%3D%3D)\n\nAllMyCircuits is intended to be a threadsafe-ish circuit breaker implementation for Ruby.\nSee [Martin Fowler's article on the Circuit Breaker pattern for more info](http://martinfowler.com/bliki/CircuitBreaker.html).\n\n# Usage\n\n    class MyService\n      include Singleton\n\n      def initialize\n        @circuit_breaker = AllMyCircuits::Breaker.new(\n          name: \"my_service\",\n          watch_errors: [Timeout::Error],               # defaults to AllMyCircuits::Breaker.net_errors,\n                                                        #   which includes typical net/http and socket errors\n          sleep_seconds: 10,                            # leave circuit open for 10 seconds, than try to call the service again\n          strategy: AllMyCircuits::Strategies::PercentageOverWindowStrategy.new(\n            requests_window: 100,                       # number of requests to calculate the average failure rate for\n            failure_rate_percent_threshold: 25          # open circuit if 25% or more requests within 100-request window fail\n                                                        #   must trip open again if the first request fails\n          }\n        )\n      end\n\n      def run\n        begin\n          @breaker.run do\n            Timeout.timeout(1.0) { my_risky_call }\n          end\n        rescue AllMyCircuits::BreakerOpen =\u003e e\n          # log me somewhere\n        rescue\n          # uh-oh, risky call failed once\n        end\n      end\n    end\n\n# Testing\n\nSo, what have we got:\n\n  * Time-sensitive code: ...check\n  * Concurrent code:     ...check\n\nDude, that's a real headache for someone who's not confortable enough with concurrent code.\nI haven't figured any awesome way of automated testing in this case.\nSo, in the [script](https://github.com/remind101/all_my_circuits/tree/master/script) folder, there are:\n\n  * [fake_service.rb](https://github.com/remind101/all_my_circuits/blob/master/script/fake_service.rb)\n  * [graphing_stress_test.rb](https://github.com/remind101/all_my_circuits/blob/master/script/graphing_stress_test.rb)\n\n## fake_service.rb\n\nthe Fake Service has 3 modes of operation: `up` (default), `die` and `slowdown`.\n\n  * `up` (default) - http://localhost:8081/up - normal mode of operation, latency up to 50ms\n  * `die` - http://localhost:8081/die - exceptions are raised left and right, slight delay in response\n  * `slowdown` - http://localhost:8081/slowdown - successful responses with a significant delay.\n\n## Graphing Stress Test\n\nruns `WORKERS` number of workers which continuously hit http://localhost:8081. Graphs are served at http://localhost:8080.\nThis app allows to catch incorrect circuit breaker behavior visually.\n\n# Logging\n\nLogger can be configured by setting `AllMyCircuits.logger`.\nDefault log device is STDERR, and default level is ERROR (can be overridden with `ALL_MY_CIRCUITS_LOG_LEVEL` environment variable).\n\n# TODO\n\n  * global controls through redis?\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fremind101%2Fall_my_circuits","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fremind101%2Fall_my_circuits","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fremind101%2Fall_my_circuits/lists"}