简体   繁体   English

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

[英]Resque worker failing with PostgreSQL server

I've managed to set up my workers and they used to execute without issue (in development) but now they don't in either production or development (I'm guessing after changing from SQlite3 to PostgreSQL). 我已经成功设置了我的工作人员并且他们曾经没有问题(在开发中)执行,但现在他们不在生产或开发中(我猜测从SQlite3更改为PostgreSQL之后)。

When I run a rake command to run the workers with rake resque:work QUEUE=* I get the following error and stack trace: 当我运行rake命令来运行rake resque:work QUEUE=*的worker rake resque:work QUEUE=*我得到以下错误和堆栈跟踪:

getaddrinfo: nodename nor servname provided, or not known

I get the following errors when running heroku rake resque:work QUEUE=* in the console to test pending workers in the queue. 运行heroku rake resque:work QUEUE=*时出现以下错误heroku rake resque:work QUEUE=*在控制台中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

And for my Facebook worker: 对于我的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)) 

Why do I get different errors in different environments? 为什么我在不同的环境中会遇到不同的错误? My initializer files look like: 我的初始化文件看起来像:

Should I add ENV specifications here? 我应该在这里添加ENV规范吗?

Resque.rb 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 Redis.rb

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

My environments/production.rb file has no reference to Redis and my environments/development.rb file has this for Redis setup: 我的environment / production.rb文件没有引用Redis,我的环境/ development.rb文件有Redis设置:

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

Adding the following to my Rakefile fixed a similar problem for me: 将以下内容添加到我的Rakefile中为我修复了类似的问题:

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

This reconnects PostgreSQL before Resque forks its process to create a worker. 这会在Resque之前重新连接PostgreSQL,从而创建一个worker。

It looks like your app can not connect to Redis server. 您的应用看起来无法连接到Redis服务器。 Did you provide valid connection details for production environment? 您是否提供了生产环境的有效连接详细信息? Is you Redis server available? 你有Redis服务器吗? Isn't it behind firewall are some private network? 是不是它背后的防火墙是一些私人网络?

I think it might be same issue with you production PostgreSQL server. 我认为生产PostgreSQL服务器可能会遇到同样的问题。

I've changed the initializers to the following and it now works on localhost, so @mirtinciu was right about the server connection. 我已经将初始化程序更改为以下内容,它现在可以在localhost上运行,所以@mirtinciu对服务器连接是正确的。 Still need to figure out what is wrong on the production server. 还需要弄清楚生产服务器上有什么问题。

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

我认为它是重复的,它通过恢复ActiveRecord连接来解决: Rails Resque worker失败了PGError:服务器意外关闭了连接

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM