Skip to content

Instantly share code, notes, and snippets.

@jkeck
Last active May 18, 2016 17:50
Show Gist options
  • Save jkeck/a973a12d2ea8b2bc4f85e067c9fb4724 to your computer and use it in GitHub Desktop.
Save jkeck/a973a12d2ea8b2bc4f85e067c9fb4724 to your computer and use it in GitHub Desktop.
Faraday Timeout Example
require 'faraday'
conn = Faraday.new(url: 'http://localhost:3000') do |faraday|
faraday.request :url_encoded
faraday.response :logger
faraday.adapter Faraday.default_adapter
faraday.request :multipart
end
conn.post do |req|
req.url '/test_timout'
req.options.timeout = 20
req.options.open_timeout = 20
end
class TestRailsController
# post 'test_timeout' => 'test_rails_controller#test_timeout'
def test_timeout
sleep(25) # This raises Faraday::TimeoutError. sleep(19) will get to the response below
render text: 'Got response'
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment