https://github.com/grantbirki/ruby-retry-examples
A sandbox repository containing examples of Ruby retry logic
https://github.com/grantbirki/ruby-retry-examples
examples retry ruby sandbox
Last synced: 2 months ago
JSON representation
A sandbox repository containing examples of Ruby retry logic
- Host: GitHub
- URL: https://github.com/grantbirki/ruby-retry-examples
- Owner: GrantBirki
- License: mit
- Created: 2024-03-21T16:13:24.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2024-05-16T21:59:22.000Z (about 2 years ago)
- Last Synced: 2025-03-28T17:08:47.053Z (over 1 year ago)
- Topics: examples, retry, ruby, sandbox
- Language: Shell
- Homepage:
- Size: 5.38 MB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
- Codeowners: .github/CODEOWNERS
Awesome Lists containing this project
README
# ruby-retry-examples 🔄
A sandbox repository containing examples of Ruby retry logic
## Setup 🛠
Run `script/bootstrap` to install dependencies
## Running the examples 🏃♂
Find an example you would like to run in the `examples/` directory and run it with:
```bash
bundle exec ruby examples/.rb
```
## Best ⭐
My favorite flavor of retry logic can be found in the [`examples/app_log_only.rb`](examples/app_log_only.rb) file. It demonstrates a dead simple retry method that comes with a `:default` context and you provide your own logger.
Note: If you are going to use the `examples/app_log_only.rb` example, and want to capture the last exception that is rais (i.e you ran out of retries) here is how you can do it:
```ruby
begin
Retryable.with_context(:default) do
puts "attempting a call to the faulty service..."
fs.call
end
rescue StandardError => e
# you have to capture the entire block other wise it will interfere with the retry logic
puts "ran out of retries, here is the exception: #{e}"
end
```