Resque工作者使用PostgreSQL服务器失败

Sim*_*ton 10 postgresql ruby-on-rails heroku resque redis

我已经成功设置了我的工作人员,他们曾经没有问题(在开发中)执行,但现在他们不在生产或开发中(我猜测从SQlite3更改为PostgreSQL之后).

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

getaddrinfo: nodename nor servname provided, or not known
Run Code Online (Sandbox Code Playgroud)

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
Run Code Online (Sandbox Code Playgroud)

对于我的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)) 
Run Code Online (Sandbox Code Playgroud)

为什么我在不同的环境中会遇到不同的错误?我的初始化文件看起来像:

我应该在这里添加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 }
Run Code Online (Sandbox Code Playgroud)

Redis.rb

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

我的environment/production.rb文件没有引用Redis,我的环境/ development.rb文件有Redis设置:

ENV["REDISTOGO_URL"] = 'redis://username:password@my.host:6789' 
Run Code Online (Sandbox Code Playgroud)

Car*_*auf 29

将以下内容添加到我的Rakefile中为我修复了类似的问题:

task "resque:setup" => :environment do
  Resque.before_fork = Proc.new { ActiveRecord::Base.establish_connection }
end
Run Code Online (Sandbox Code Playgroud)

这会在Resque之前重新连接PostgreSQL,从而创建一个worker.