Resque 工作线程因 PostgreSQL 服务器而失败

发布于 2024-12-10 07:17:59 字数 2500 浏览 0 评论 0原文

我已经成功地设置了我的工作人员,他们过去可以毫无问题地执行(在开发中),但现在他们在生产或开发中都没有(我猜是从 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< /em> 文件没有对 Redis 的引用,而我的 environments/development.rb 文件包含以下 Redis 设置:

ENV["REDISTOGO_URL"] = 'redis://username:[email protected]:6789' 

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).

When I run a rake command to run the workers with rake resque:work QUEUE=* I get the following error and stack trace:

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.

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:

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?

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

My environments/production.rb file has no reference to Redis and my environments/development.rb file has this for Redis setup:

ENV["REDISTOGO_URL"] = 'redis://username:[email protected]:6789' 

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

匿名的好友 2024-12-17 07:17:59

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

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

这会在 Resque 分叉其进程以创建工作程序之前重新连接 PostgreSQL。

Adding the following to my Rakefile fixed a similar problem for me:

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.

守不住的情 2024-12-17 07:17:59

您的应用程序似乎无法连接到 Redis 服务器。您是否提供了生产环境的有效连接详细信息?你的Redis服务器可用吗?防火墙后面不是有一些专用网络吗?

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

It looks like your app can not connect to Redis server. Did you provide valid connection details for production environment? Is you Redis server available? Isn't it behind firewall are some private network?

I think it might be same issue with you production PostgreSQL server.

一江春梦 2024-12-17 07:17:59

我已将初始化程序更改为以下内容,现在它可以在本地主机上运行,​​因此 @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

I've changed the initializers to the following and it now works on localhost, so @mirtinciu was right about the server connection. 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
丘比特射中我 2024-12-17 07:17:59

我认为这是重复的,可以通过恢复 ActiveRecord 连接来解决:
Rails Resque 工作线程因 PGError 失败:服务器关闭了连接意外

I think it's a duplicate and it is solved by restoring the ActiveRecord connection:
Rails Resque workers fail with PGError: server closed the connection unexpectedly

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文