QA@IT

development環境以外で「rake resque:work」が動かない(起動しない)

3479 PV

development環境では正常に起動し、ワーカー処理も問題なく行われるのですが、staging環境でワーカーを起動しようとすると下記のエラーになります。
何か原因として考えられるものはありますでしょうか?

  • エラーメッセージ

(PictureSweeperActionController::Caching::Sweeperを継承したキャッシュ削除用のsweeperです)

bundle exec rake environment resque:work QUEUE='*' RAILS_ENV=staging --trace
/home/baker/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/blankslate-3.1.2/lib/blankslate.rb:51: warning: undefining `object_id' may cause serious problems
** Invoke environment (first_time)
** Execute environment
** Invoke resque:work (first_time)
** Invoke resque:preload (first_time)
** Invoke resque:setup (first_time)
** Invoke environment 
** Execute resque:setup
** Execute resque:preload
rake aborted!
uninitialized constant PictureSweeper
/home/baker/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/actionpack-3.2.12/lib/action_controller/caching/sweeping.rb:41:in `const_get'
/home/baker/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/actionpack-3.2.12/lib/action_controller/caching/sweeping.rb:41:in `block in cache_sweeper'
/home/baker/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/actionpack-3.2.12/lib/action_controller/caching/sweeping.rb:39:in `each'
/home/baker/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/actionpack-3.2.12/lib/action_controller/caching/sweeping.rb:39:in `cache_sweeper'
/home/baker/viewer-staging.cakes.mu/app/controllers/application_controller.rb:2:in `<class:ApplicationController>'
/home/baker/viewer-staging.cakes.mu/app/controllers/application_controller.rb:1:in `<top (required)>'
/home/baker/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/activesupport-3.2.12/lib/active_support/dependencies.rb:251:in `require'
/home/baker/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/activesupport-3.2.12/lib/active_support/dependencies.rb:251:in `block in require'
/home/baker/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/activesupport-3.2.12/lib/active_support/dependencies.rb:236:in `load_dependency'
/home/baker/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/activesupport-3.2.12/lib/active_support/dependencies.rb:251:in `require'
/home/baker/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/activesupport-3.2.12/lib/active_support/dependencies.rb:359:in `require_or_load'
/home/baker/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/activesupport-3.2.12/lib/active_support/dependencies.rb:313:in `depend_on'
/home/baker/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/activesupport-3.2.12/lib/active_support/dependencies.rb:225:in `require_dependency'
/home/baker/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/railties-3.2.12/lib/rails/engine.rb:439:in `block (2 levels) in eager_load!'
/home/baker/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/railties-3.2.12/lib/rails/engine.rb:438:in `each'
/home/baker/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/railties-3.2.12/lib/rails/engine.rb:438:in `block in eager_load!'
/home/baker/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/railties-3.2.12/lib/rails/engine.rb:436:in `each'
/home/baker/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/railties-3.2.12/lib/rails/engine.rb:436:in `eager_load!'
/home/baker/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/resque-1.24.1/lib/resque/tasks.rb:61:in `block (2 levels) in <top (required)>'
/home/baker/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/rake-10.0.4/lib/rake/task.rb:246:in `call'
/home/baker/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/rake-10.0.4/lib/rake/task.rb:246:in `block in execute'
/home/baker/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/rake-10.0.4/lib/rake/task.rb:241:in `each'
/home/baker/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/rake-10.0.4/lib/rake/task.rb:241:in `execute'
/home/baker/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/rake-10.0.4/lib/rake/task.rb:184:in `block in invoke_with_call_chain'
/home/baker/.rbenv/versions/1.9.3-p327/lib/ruby/1.9.1/monitor.rb:211:in `mon_synchronize'
/home/baker/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/rake-10.0.4/lib/rake/task.rb:177:in `invoke_with_call_chain'
/home/baker/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/rake-10.0.4/lib/rake/task.rb:205:in `block in invoke_prerequisites'
/home/baker/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/rake-10.0.4/lib/rake/task.rb:203:in `each'
/home/baker/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/rake-10.0.4/lib/rake/task.rb:203:in `invoke_prerequisites'
/home/baker/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/rake-10.0.4/lib/rake/task.rb:183:in `block in invoke_with_call_chain'
/home/baker/.rbenv/versions/1.9.3-p327/lib/ruby/1.9.1/monitor.rb:211:in `mon_synchronize'
/home/baker/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/rake-10.0.4/lib/rake/task.rb:177:in `invoke_with_call_chain'
/home/baker/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/rake-10.0.4/lib/rake/task.rb:170:in `invoke'
/home/baker/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/rake-10.0.4/lib/rake/application.rb:143:in `invoke_task'
/home/baker/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/rake-10.0.4/lib/rake/application.rb:101:in `block (2 levels) in top_level'
/home/baker/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/rake-10.0.4/lib/rake/application.rb:101:in `each'
/home/baker/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/rake-10.0.4/lib/rake/application.rb:101:in `block in top_level'
/home/baker/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/rake-10.0.4/lib/rake/application.rb:110:in `run_with_threads'
/home/baker/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/rake-10.0.4/lib/rake/application.rb:95:in `top_level'
/home/baker/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/rake-10.0.4/lib/rake/application.rb:73:in `block in run'
/home/baker/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/rake-10.0.4/lib/rake/application.rb:160:in `standard_exception_handling'
/home/baker/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/rake-10.0.4/lib/rake/application.rb:70:in `run'
/home/baker/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/rake-10.0.4/bin/rake:33:in `<top (required)>'
/home/baker/.rbenv/versions/1.9.3-p327/bin/rake:23:in `load'
/home/baker/.rbenv/versions/1.9.3-p327/bin/rake:23:in `<main>'
Tasks: TOP => resque:work => resque:preload
  • config/environments/staging.rb設定値
  config.cache_classes = true
  config.consider_all_requests_local       = false
  config.action_controller.perform_caching = true
  config.serve_static_assets = true
  config.assets.compress = true
  config.assets.compile = false
  config.assets.digest = true
  config.assets.precompile += %w( viewer.js viewer.css  )
  config.i18n.fallbacks = true
  config.active_support.deprecation = :notify
  config.threadsafe!
  • config/initializers/resque.rb
Resque.redis = Redis.new(host: "localhost", port: 6379)
  • 環境情報
ruby 1.9.3p327 (2012-11-10 revision 37606) [x86_64-linux]
Rails 3.2.12
resque-1.24.1
  • config/environments/staging.rbのconfig.cache_classes を falseにするとどうなりますか? 併せてconfig/environments/development.rbのconfig.cache_classes は falseだと思いますが trueにした場合どうなりますか? -
  • stagingとdevelopmentのconfig.cache_classesをそれぞれfalseとtrueに変えてみましたが、どちらも挙動は変わらないですね。。 -

回答

ひょっとしてローカルの開発環境がruby 2.0.0ではないですか?1.9.3との間でconst_getの挙動に違いがあります。

http://spring-mt.tumblr.com/post/45097795854/ruby-2-0-const-get

もし

cache_sweeper :picture_sweeper

のようにSymbolで指定しているのだとすると、

cache_sweeper ::PictureSweeper

で回避できないでしょうか。(ActionController::Caching::Sweeperの該当部分のソースをパッと見ただけで試してはいません)

編集 履歴 (0)
  • おっしゃるとおりdevelopmentはRuby 2.0.0で、cache_sweeperもシンボルで指定していたので、::PictureSweeperの表記に変えてみたのですが、事象は変わりませんでした。。 -
  • picture_sweeper.rbはどこに置いてありますか?もし一般的なパスではない場合、application.rbでconfig.eager_load_paths << "#{config.root}/lib"などとして追加してありますか?picture_sweeper.rbはautoloadに任せていますかそれとも明示的にrequireしていますか? -
  • `app/sweepers`に置いて`config.autoload_paths += %W(#{config.root}/sweepers)`の設定をしてautoladですね。あとは`application_controller.rb`に`cache_sweeper :picture_sweeper`を記述しています。 -
ウォッチ

この質問への回答やコメントをメールでお知らせします。