我今天在本地设置了 resque-pool,我注意到了一些奇怪的行为。我之前已经启动并运行了普通的旧resque没问题。我的工作失败了,因为找不到记录。当我深入研究时,我发现这是因为工作人员正在使用测试配置进行设置。我在本地使用 foreman/heroku,我的 .env 文件设置了环境 RACK_ENV=development
,我还尝试添加了一个 RACK_ENV=development
示例设置输出
[OKAY] Loaded ENV .env File as KEY=VALUE Format
5:01:34 PM web.1 | Puma starting in single mode...
5:01:34 PM web.1 | * Version 3.6.0 (ruby 2.3.0-p0), codename: Sleepy Sunday Serenity
5:01:34 PM web.1 | * Min threads: 5, max threads: 5
5:01:34 PM web.1 | * Environment: development
5:01:34 PM worker.1 | resque-pool-manager[curio-api][1751]: Resque Pool running in development environment
5:01:36 PM web.1 | * Listening on tcp://0.0.0.0:3000
5:01:36 PM web.1 | Use Ctrl-C to stop
5:01:36 PM worker.1 | resque-pool-manager[curio-api][1751]: started manager
我的任务/resque.rake 文件
require 'resque/pool/tasks'
# this task will get called before resque:pool:setup
# and preload the rails environment in the pool manager
task "resque:setup" => :environment do
# generic worker setup, e.g. Hoptoad for failed jobs
end
task "resque:pool:setup" => :environment do
# close any sockets or files in pool manager
ActiveRecord::Base.connection.disconnect!
# and re-open them in the resque worker parent
Resque::Pool.after_prefork do |job|
ActiveRecord::Base.establish_connection
end
end
我不确定为什么没有选择环境变量。我也有点惊讶 resque-pool 默认测试。我在 rails 5.0 api only 应用程序中使用 0.6.0。我确定我一定在做一些愚蠢的事情,但我看不出它是什么
以防万一它有帮助,搞乱byebug
✗ resque-pool
[7, 16] in /Users/conornugent/Dev/neighbourwood/curio/curio-api/lib/tasks/resque.rake
7: end
8:
9: task "resque:pool:setup" => :environment do
10: # close any sockets or files in pool manager
11: byebug
=> 12: ActiveRecord::Base.connection.disconnect!
13: # and re-open them in the resque worker parent
14: Resque::Pool.after_prefork do |job|
15: ActiveRecord::Base.establish_connection
16: end
(byebug) Rails.env
"test"
(byebug) ActiveRecord::Base.connection.current_database
"curio-api_test"
我发布了一个关于此的问题,但我猜这可能是我正在做的事情,所以这可能更适合我的查询
最佳答案
我从来没有真正弄清楚为什么 bundle exec resque-pool
默认为“test”(不知何故 Rails.env 正在返回测试)但是我的个人资料从
worker: bundle exec resque-pool
以下内容
worker: bundle exec rake resque:pool
确保环境设置正确。如果有人对为什么 bundle exec resque-pool
表现如此奇怪有任何想法,请告诉我
关于ruby-on-rails - resque-pool 默认为测试环境,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39787176/