Resque工作者在PostgreSQL服务器上失败

10

我已经成功设置了我的工作进程,并且它们在开发环境中能够正常执行,但现在无论是生产环境还是开发环境都不能执行(我猜测是从 SQlite3 切换到 PostgreSQL 后出现的问题)。

当我运行 rake 命令以rake resque:work QUEUE=*来运行工作进程时,我会得到以下错误和堆栈跟踪:

getaddrinfo: nodename nor servname provided, or not known

当我在控制台中运行heroku rake resque:work QUEUE=*来测试队列中待处理的工作时,我会得到以下错误信息。

Class         SentimentJob
Arguments     [4, 5, 6]
Exception     ActiveRecord::StatementInvalid
Error         PGError: server closed the connection unexpectedly This probably means
              the server terminated abnormally before or while processing the request.
              : SELECT a.attname, format_type(a.atttypid, a.atttypmod), d.adsrc,
              a.attnotnull FROM pg_attribute a LEFT JOIN pg_attrdef d ON a.attrelid =
              d.adrelid AND a.attnum = d.adnum WHERE a.attrelid = '"taggings"'::regclass
              AND a.attnum > 0 AND NOT a.attisdropped ORDER BY a.attnum

还有针对我的 Facebook 员工:

Class         FBConnectionsJob
Arguments     1
Exception     OpenSSL::SSL::SSLError
Error         SSL_connect returned=1 errno=0 state=SSLv3 read server certificate B:
              certificate verify failed

Class         FBConnectionsJob
Arguments     1
Exception     ActiveRecord::StatementInvalid
Error         PGError: server closed the connection unexpectedly This probably means
              the server terminated abnormally before or while processing the request.
              : SELECT tablename FROM pg_tables WHERE schemaname = ANY
              (current_schemas(false)) 
为什么在不同环境下会出现不同的错误?我的初始化文件看起来像这样:
我应该在这里添加ENV规范吗?
Resque.rb
uri = URI.parse(ENV["REDISTOGO_URL"])
Resque.redis = Redis.new(:host => uri.host, :port => uri.port, :password => uri.password)
Dir["#{Rails.root}/app/jobs/*.rb"].each { |file| require file }

Redis.rb

uri = URI.parse(ENV["REDISTOGO_URL"])
REDIS = Redis.new(:host => uri.host, :port => uri.port, :password => uri.password)
Resque.redis = REDIS

我的environments/production.rb文件中没有与Redis相关的引用,而我的environments/development.rb文件则包含了以下Redis设置:

ENV["REDISTOGO_URL"] = 'redis://username:password@my.host:6789' 

在我看来,问题似乎出在数据库连接上,而不是Redis。你使用了某种非标准的设置吗? - Neil Middleton
4个回答

29

将以下内容添加到我的Rakefile中可以解决我遇到的类似问题:

task "resque:setup" => :environment do
  Resque.before_fork = Proc.new { ActiveRecord::Base.establish_connection }
end

在 Resque fork 进程创建 worker 之前,这会重新连接 PostgreSQL。


0

我已将初始化程序更改为以下内容,现在它可以在本地主机上运行,所以@mirtinciu关于服务器连接的说法是正确的。仍需要弄清楚生产服务器上出了什么问题。

if Rails.env.development?
  uri = URI.parse(ENV["REDISTOGO_URL"])
  Resque.redis = Redis.new(:host => 'localhost', :port => '6379')
else
  uri = URI.parse(ENV["REDISTOGO_URL"])
  Resque.redis = Redis.new(:host => uri.host, :port => uri.port, :password => uri.password)
end

0

看起来你的应用无法连接到Redis服务器。你是否为生产环境提供了有效的连接细节?你的Redis服务器可用吗?它是否在防火墙或私有网络后面?

我认为你的生产PostgreSQL服务器可能存在同样的问题。


我确实可以在Heroku和开发环境中访问Redis服务器 - 我没有更改本地主机环境,因此它不会改变。 - Simpleton
1
我有什么遗漏吗?我没有看到任何与Redis相关的错误。 - Carl Zulauf

0

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接