Muxer
Muxer is a gem to allow web requests to run in parallel with seperate timeouts per request, in addition to an optional global timeout for all of the requests.
For example:
- Request 1 (Internal API) - 5 second timeout
- Request 2 (External) - 1 second timeout
- Request 3 (External) - 1 second timeout
- Request 4 (External) - 1 second timeout
Requests 2-4 will be allowed to continue waiting after their timeouts if we are still waiting on Request 1; however, if Request 1 comes back in half a second, we will finish ALL requests at the 1 second timeout. Any requests not finished within the timeouts will be added to the :failed array in the response.
Installation
Add this line to your application's Gemfile:
gem 'muxer'
And then execute:
$ bundle
Or install it yourself as:
$ gem install muxer
Usage
response = Muxer.execute do |muxer|
muxer.add_url "http://www.rubydoc.info"
muxer.add_url "https://www.google.com"
end
response[:failed] == []
response[:succeeded] == [
Muxer::Request(url: "http://www.rubydoc.info"),
Muxer::Request(url: "https://www.google.com")
]
Contributing
- Fork it ( https://github.com/[my-github-username]/muxer/fork )
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create a new Pull Request