https://github.com/renderedtext/outside
Takes care of timeouts and retries for given blocks of code.
https://github.com/renderedtext/outside
gem rails retries semaphore-open-source
Last synced: about 2 months ago
JSON representation
Takes care of timeouts and retries for given blocks of code.
- Host: GitHub
- URL: https://github.com/renderedtext/outside
- Owner: renderedtext
- License: mit
- Created: 2016-07-07T13:10:17.000Z (almost 10 years ago)
- Default Branch: master
- Last Pushed: 2016-09-26T15:30:44.000Z (over 9 years ago)
- Last Synced: 2025-06-04T04:16:34.546Z (about 1 year ago)
- Topics: gem, rails, retries, semaphore-open-source
- Language: Ruby
- Homepage:
- Size: 17.6 KB
- Stars: 0
- Watchers: 12
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
# Outside

Watches after your blocks of code and makes sure that they find their way back home.
## Description
Currently wraps blocks of code (for example those handling outbound connections) into a timeout block. The idea is to add all of the generic things that should wrap connections and similar cases right here. Feel free to expand the gem.
## Installation
Add this line to your application's Gemfile:
```ruby
gem 'outside'
```
And then execute:
$ bundle
Or install it yourself as:
$ gem install outside
## Usage
```
Outside.go(options) do
# code
end
```
Default behavior is the following: if the block passed to the method does not finish executing in the given time (default is 5 seconds), it will be stopped and a `Timeout::Error` will be raised.
Possible options for changing the default behavior are:
- `:iteration_limit` - Timeout duration for one iteration. Default value is 5 seconds.
- `:total_limit` - Timeout duration for all of iterations (first one plus the retries). Default value is 3600 seconds (1 hour).
- `:retry_count` - Retry count. Default is 0.
- `:interval_duration` - Interval between retries. Default is 0.
- `:interval_increment` - Value by which the interval is incremented between retries. Default is 0.
- `:interval_factor` - Factor by which the interval is multiplied between retries. Default is 1.
- `:interval_randomness` - Range of randomness for the random factor (see interval calculation below). It is a number between 0 and 1. Random factor will be a number in the range of (1 - interval_randomness, 1 + interval_randomness). Default is 0, meaning that the random factor will be 1 and therefore the interval will remain unchanged.
- `:interval_limit` - Maximum interval value. Not set by default.
- `:handle_timeout` - Sets if `Timeout::Error` will be raised in case of a timeout. If it is false, it will not raise anything and it will return `nil`. Default value is true.
All temporal values are in seconds.
Interval calculation:
```
iteration_interval = random_factor * (interval_factor * previous_iteration_interval + interval_increment)
```
Example with options:
```
options = {
:iteration_limit => 10,
:retry_count => 3,
:interval_duration => 5
}
Outside.go(options) do
# code
end
```