Faraday timeout

后端 未结 2 1496
北海茫月
北海茫月 2021-02-14 13:16

I\'ve searched the docs and other places online and cannot seem to come up with the proper way to set the timeout option for Faraday. Anyone have the answer?

I\'ve tried

相关标签:
2条回答
  • 2021-02-14 13:43

    The Faraday README currently contains this example using a block style:

    conn.get do |req|
      req.url '/search'
      req.options[:timeout] = 5           # open/read timeout in seconds
      req.options[:open_timeout] = 2      # connection open timeout in seconds
    end
    

    If this doesn't work for you, perhaps you should file a ticket over on Github.

    0 讨论(0)
  • 2021-02-14 13:45

    Well it seems I figured it out. If I pass the timeout option into the initializer, it seems to work:

      options = {
        :timeout      => 20,
        :open_timeout => 20
      }
      conn = FaradayStack.build(url, options)
      conn.headers[:user_agent] = AppConfig.user_agent
      conn.get.body
    
    0 讨论(0)
提交回复
热议问题