【问题标题】:Heroku, Rails, Resque, Redis: All jobs failing because of Errno::ETIMEDOUTHeroku、Rails、Resque、Redis:所有作业都因 Errno::ETIMEDOUT 而失败
【发布时间】:2017-04-16 16:06:14
【问题描述】:

我在 heroku 上有一个 rails 应用程序,它使用 Resque.enqueu 使用 Redis 和 redistogo 安排后台作业。

以前工作正常,但我现在注意到它们都失败了一段时间(几周,100% 的工作)。

我得到的错误:

Exception Errno::ETIMEDOUT 错误连接超时 - connect(2)

还有堆栈跟踪:

> /app/vendor/ruby-2.0.0/lib/ruby/2.0.0/net/http.rb:878:in `initialize'
> /app/vendor/ruby-2.0.0/lib/ruby/2.0.0/net/http.rb:878:in `open'
> /app/vendor/ruby-2.0.0/lib/ruby/2.0.0/net/http.rb:878:in `block in
> connect' /app/vendor/ruby-2.0.0/lib/ruby/2.0.0/timeout.rb:52:in
> `timeout' /app/vendor/ruby-2.0.0/lib/ruby/2.0.0/net/http.rb:877:in
> `connect' /app/vendor/ruby-2.0.0/lib/ruby/2.0.0/net/http.rb:862:in
> `do_start' /app/vendor/ruby-2.0.0/lib/ruby/2.0.0/net/http.rb:851:in
> `start' /app/vendor/ruby-2.0.0/lib/ruby/2.0.0/net/http.rb:1373:in
> `request' /app/vendor/ruby-2.0.0/lib/ruby/2.0.0/net/http.rb:1131:in
> `get'
> /app/vendor/bundle/ruby/2.0.0/gems/activeresource-4.0.0/lib/active_resource/connection.rb:121:in `block in request'
> /app/vendor/bundle/ruby/2.0.0/gems/activesupport-4.2.1/lib/active_support/notifications.rb:164:in
> `block in instrument'
> /app/vendor/bundle/ruby/2.0.0/gems/activesupport-4.2.1/lib/active_support/notifications/instrumenter.rb:20:in
> `instrument'
> /app/vendor/bundle/ruby/2.0.0/gems/activesupport-4.2.1/lib/active_support/notifications.rb:164:in
> `instrument'
> /app/vendor/bundle/ruby/2.0.0/gems/activeresource-4.0.0/lib/active_resource/connection.rb:118:in `request'
> /app/vendor/bundle/ruby/2.0.0/gems/shopify_api-4.0.6/lib/active_resource/connection_ext.rb:13:in `request_with_detailed_log_subscriber'
> /app/vendor/bundle/ruby/2.0.0/gems/activeresource-4.0.0/lib/active_resource/connection.rb:82:in
> `block in get'
> /app/vendor/bundle/ruby/2.0.0/gems/activeresource-4.0.0/lib/active_resource/connection.rb:216:in `with_auth'
> /app/vendor/bundle/ruby/2.0.0/gems/activeresource-4.0.0/lib/active_resource/connection.rb:82:in
> `get'
> /app/vendor/bundle/ruby/2.0.0/gems/activeresource-4.0.0/lib/active_resource/custom_methods.rb:57:in
> `get'
> /app/vendor/bundle/ruby/2.0.0/gems/shopify_api-4.0.6/lib/shopify_api/countable.rb:4:in
> `count' /app/app/models/shop.rb:263:in `unscanned_customers'
> /app/app/models/shop.rb:230:in `shopify_customers'
> /app/app/models/shop.rb:144:in `bulk_scan'
> /app/app/workers/bulk_scanner.rb:16:in `perform'

我在想这可能与没有正确连接到 Redis 或 redistogo 有关。以下是我拥有的相关初始化程序代码:

resque.rb:

Resque.redis = RedisConnection.connection

redis_connection.rb:

class RedisConnection
  def self.close
    connection.quit
  end

  def self.connection
    @connection ||= new_connection
  end

  def self.new_connection
    uri = URI.parse(ENV['REDISTOGO_URL'] || 'redis://localhost:6379/')

    Redis.new(host: uri.host,
              port: uri.port,
              password: uri.password,
              thread_safe: true,
              :timeout => 1)
  end
end

如果我在我的应用程序中调用 Resque.redis 或 @connection,它会返回一个 Redis 实例。还有什么会导致此连接错误?我可以在哪里进行故障排除?

【问题讨论】:

    标签: ruby-on-rails heroku redis resque redistogo


    【解决方案1】:

    查看 Backtrace,会不会是 Shopify API 连接超时? 看起来unscanned_customers 应该是一个可数的 Shopify 集合,并且在尝试检索客户时会出现问题。

    我会从这里开始调试: > 'count' /app/app/models/shop.rb:263:in 'unscanned_customers'

    另外,我会尝试使用私有应用 API 密钥和密码从服务器连接到 Shopify:

    shop_url = "https://#{API_KEY}:#{PASSWORD}@SHOP_NAME.myshopify.com/admin"
    ShopifyAPI::Base.site = shop_url
    

    如果需要,请参阅 Shopify API 以获取更多详细信息Shopify API Readme

    这将有助于隔离连接问题。

    干杯。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-09-07
      • 2015-10-08
      • 1970-01-01
      • 2015-03-24
      • 1970-01-01
      • 2013-03-31
      • 1970-01-01
      相关资源
      最近更新 更多