我在Heroku上使用Resque.Enqueu在使用Redis和Redistogo安排后台作业的Heroku上有一个Rails应用程序。
工作曾经正常工作,但我现在注意到它们已经失败了一段时间(几周,占工作的100%)。
我遇到的错误:
异常errno :: eTimedout错误连接时机超时 - 连接(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或Repistogo有关。这是我拥有的相关初始化代码:
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实例。还有什么会导致此连接错误?我在哪里可以进行故障排除?
看回溯,它可以是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
它将有助于隔离连接问题。
欢呼。