2016-09-30 40 views
1

我今天在本地设置了resque-pool,我注意到一些奇怪的行为。我以前得到普通的老式复苏并没有问题。我的工作失败,因为找不到记录。当我挖掘到这一点时,我发现这是因为工人正在设置测试配置。我使用领班/ Heroku的地方和我.ENV文件设置环境RACK_ENV=development,我也尝试添加了RACK_ENV=developmentresque-pool默认为测试环境

样品设置输出

[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 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

回答

0

我从来没有真正得到为什么bundle exec resque-pool默认为“测试”的底部(不知何故Rails.env正在返回测试),但是从

worker: bundle exec resque-pool 

交换我的个人资料如下

worker: bundle exec rake resque:pool 

确保环境被正确设置。如果任何人有任何想法,为什么bundle exec resque-pool表现得如此奇怪,请让我知道