{"id":13764049,"url":"https://github.com/VividCortex/robustly","last_synced_at":"2025-05-10T17:31:24.548Z","repository":{"id":9392247,"uuid":"11254931","full_name":"VividCortex/robustly","owner":"VividCortex","description":"Run functions resiliently in Go, catching and restarting panics","archived":false,"fork":false,"pushed_at":"2023-12-12T11:14:27.000Z","size":34,"stargazers_count":158,"open_issues_count":1,"forks_count":8,"subscribers_count":18,"default_branch":"master","last_synced_at":"2024-11-16T23:32:30.124Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Go","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/VividCortex.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2013-07-08T13:27:10.000Z","updated_at":"2024-10-15T10:13:04.000Z","dependencies_parsed_at":"2024-06-18T17:07:59.920Z","dependency_job_id":"b0404865-4629-466b-b172-15e0fb3a0dd4","html_url":"https://github.com/VividCortex/robustly","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/VividCortex%2Frobustly","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/VividCortex%2Frobustly/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/VividCortex%2Frobustly/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/VividCortex%2Frobustly/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/VividCortex","download_url":"https://codeload.github.com/VividCortex/robustly/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253453285,"owners_count":21911067,"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":[],"created_at":"2024-08-03T15:01:10.812Z","updated_at":"2025-05-10T17:31:23.666Z","avatar_url":"https://github.com/VividCortex.png","language":"Go","readme":"# robustly\n\nRobustly runs code resiliently, recovering from occasional errors.\nIt also gives you the ability to probabilistically inject panics into\nyour application, configuring them at runtime at crash sites of your\nchoosing. We use it at [VividCortex](https://vividcortex.com/blog/2013/07/30/writing-resilient-programs-with-go-and-robustly-run/)\nto ensure that unexpected problems don't disable our agent programs.\n\n![build](https://github.com/VividCortex/robustly/workflows/build/badge.svg)\n\n## Getting Started\n\n```sh\ngo get github.com/VividCortex/robustly\n```\n\nNow import the following in your code:\n\n```go\nimport (\n    \"github.com/VividCortex/robustly\"\n)\n\nfunc main() {\n    go robustly.Run(func() { somefunc() })\n}\n\nfunc somefunc() {\n    for {\n        // do something here that may panic\n    }\n}\n```\n\n## API Documentation\n\nView the GoDoc generated documentation [here](http://godoc.org/github.com/VividCortex/robustly).\n\n### Robustly's Purpose\n\nRobustly is designed to help make Go programs more resilient to errors\nyou don't discover until they're in the field. It is not a general-purpose\napproach and shouldn't be overused, but in specific conditions it can be valuable.\n\n![cat](http://eventingnation.com/eventingnation.com/images/2012/04/cat-helmet.jpg)\n\nImagine, for example, that you are writing a program designed to process events\nat a high rate, such as 50,000 per second. The program is stateful, and its\nvalue comes from observing the event stream for relatively long periods, such\nas several minutes, to learn its behavior. Now imagine that you introduce a\nsubtle bug into the program, which will happen extremely rarely -- once in a\nmillion. Although rare, this bug will cause a panic and crash the program.\n\nYour program will be completely useless for its intended purpose, because\nyou're likely to hit a once-in-a-million error every 20 seconds.\nHandling such errors, especially when the program will take some time and effort\nto fix and redeploy, can make the program 99.9999% useful again.\n\nRobustly is targeted towards this type of use case. Its design is inspired by\nthe `net/http` server's code, where each HTTP request is handled in a goroutine\nthat can crash without crashing the entire server.\n\nWhen Robustly handles a crash, it immediately restarts the offending code. It keeps\ntrack of how fast the code crashes, and if it crashes too quickly for too long, it\ngives up and crashes the whole program. This way once-in-a-million errors can be\nrestarted without getting into infinite loops.\n\n### Using Run\n\nTo use Run, simply wrap around the function call that represents\nthe entry point to the code you wish to catch and restart:\n\n```go\nrobustly.Run(func() { /* your code here */ }, nil)\n```\n\nTo use the optional settings of Run, pass Run a pointer to a RunOptions struct.\n\n```go\n// RunOptions is a struct to hold the optional arguments to Run.\ntype RunOptions struct {\n    RateLimit  float64       // the rate limit in crashes per second\n    Timeout    time.Duration // the timeout (after which Run will stop trying)\n    PrintStack bool          // whether to print the panic stacktrace or not\n    RetryDelay time.Duration // inject a delay before retrying the run\n}\n```\n\nDefault options are shown below:\n\n```go\nrobustly.Run(func() { /* your code here */ }, \u0026robustly.RunOptions{\n    RateLimit:  1.0,\n    Timeout:    time.Second,\n    PrintStack: false,\n    RetryDelay: 0 * time.Nanosecond,\n})\n```\n\n### Using Crash\n\nRobustly also includes `Crash()`, a way to inject panics into your code at runtime.\nTo use it, select places where you'd like to cause crashes, and add the following\nline of code:\n\n```go\nrobustly.Crash()\n```\n\nConfigure crash sites with `CrashSetup()`. Pass it a comma-separated string of crash\nsites, which are colon-separated `file:line:probability` specifications. Probability\nshould range between 0 and 1. If you pass the special spec `\"VERBOSE\"`, it will enable\nprintouts of all crash sites that are located in your code.\n\nThe idea is to match the crash sites configured in the setup with those actually\npresent in your code. For example, if you have added a crash site in the code at\nline 53 of client.go, and you'd like to crash there, as well as at line 18 of server.go:\n\n```txt\n    client.go:53:.003,server.go:18:.02\n```\n\nThat will cause a crash .003 of the time at client.go line 53, and .02 of the time\nat server.go line 18.\n\nIf you are using `robustly.Run()` to make your code resilient to errors, it is a very\ngood idea to deliberately inject errors and make sure they are indeed handled. You can\neasily miss a detail such as a potentially crashing function that is called as a goroutine.\n\n## Contributing\n\nWe only accept pull requests for minor fixes or improvements. This includes:\n\n* Small bug fixes\n* Typos\n* Documentation or comments\n\nPlease open issues to discuss new features. Pull requests for new features will be rejected,\nso we recommend forking the repository and making changes in your fork for your use case.\n\n## License\n\nThis program is (c) VividCortex 2013, and is licensed under the MIT license. Please see the LICENSE file.\n","funding_links":[],"categories":["实用工具","Utilities","公用事业公司","工具库`可以提升效率的通用代码库和工具`","Utility","工具库","實用工具"],"sub_categories":["Advanced Console UIs","Utility/Miscellaneous","Fail injection","实用程序/Miscellaneous","HTTP Clients","查询语","交流","\u003cspan id=\"高级控制台用户界面-advanced-console-uis\"\u003e高级控制台用户界面 Advanced Console UIs\u003c/span\u003e","高级控制台界面","高級控制台界面"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FVividCortex%2Frobustly","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FVividCortex%2Frobustly","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FVividCortex%2Frobustly/lists"}