【问题标题】:Faraday timeout法拉第超时
【发布时间】:2011-12-27 06:26:26
【问题描述】:

我在网上搜索了文档和其他地方,但似乎无法找到为法拉第设置超时选项的正确方法。谁有答案?

我试过了:

  conn = FaradayStack.build(url)
  conn.headers[:user_agent]   = AppConfig.user_agent
  # conn.options[:timeout]      = 20
  # conn.options[:open_timeout] = 20
  response = conn.get do |req|
    req.options = {
      :timeout      => 20,
      :open_timeout => 20
    }
  end
  response.body

似乎没有任何效果。顺便说一句,如果有区别的话,我会使用 Typhoeus 适配器。

【问题讨论】:

    标签: ruby


    【解决方案1】:

    好吧,看来我想通了。如果我将超时选项传递给初始化程序,它似乎可以工作:

      options = {
        :timeout      => 20,
        :open_timeout => 20
      }
      conn = FaradayStack.build(url, options)
      conn.headers[:user_agent] = AppConfig.user_agent
      conn.get.body
    

    【讨论】:

    【解决方案2】:

    Faraday README 目前包含这个使用块样式的示例:

    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
    

    如果这对你不起作用,也许你应该在 Github 上提交一张票。

    【讨论】:

    • 最初的问题似乎是在询问一般超时,而不是上面提到的每个请求超时。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-05-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-11-01
    • 1970-01-01
    • 2010-10-19
    相关资源
    最近更新 更多