resque-pool默认为测试环境

时间:2016-09-30 08:39:39

标签: ruby-on-rails ruby redis resque

我今天在本地设置了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 app中使用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"

我发布了一个关于此的问题,但我猜这可能是我正在做的事情,所以这可能是我的查询更合适的主页

https://github.com/nevans/resque-pool/issues/158

1 个答案:

答案 0 :(得分:0)

我从来没有真正理解为什么bundle exec resque-pool默认为'测试'(不知何故Rails.env正在返回测试)但是从

切换我的个人资料
worker: bundle exec resque-pool

以下

worker: bundle exec rake resque:pool

确保环境设置正确。如果有人对bundle exec resque-pool如此奇怪的行为有任何疑问,请告诉我