7
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

ActiveJob の queue_adapter は config/initializers/*.rb で登録してはいけない

Last updated at Posted at 2018-03-12

ActiveJob の設定に関する雑なメモ。

ActiveJob を使う際にqueue_adapterを以下のような感じで設定してしまうと、production環境であるにも関わらずアダプターが:asyncになってしまう場合がある。(なぜか上手くいく場合もあるので厄介)

config/initializers/sidekiq.rb
case Rails.env
when 'production'
  Rails.application.config.active_job.queue_adapter = :sidekiq
else
  Rails.application.config.active_job.queue_adapter = :async
end

理由は以下の記事が詳しいが、

簡単に説明すると、Railsの初期化時にRailtie#initializerconfig/initializers/*.rbよりも先に走ってしまうことで、queue_adapterが設定されていない場合のデフォルトである:async (Rails4.xであれば:inline) が設定されてしまう、ということみたい。

環境ごとに書き換えたいならconfig/environments/*.rbに書こう。(ちゃんとコメントが書いてある。)

# Use a real queuing backend for Active Job (and separate queues per environment)
# config.active_job.queue_adapter     = :resque
# config.active_job.queue_name_prefix = "application_#{Rails.env}"
7
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
7
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?