gem
# Gemfile gem 'delayed_job_active_record' gem 'daemons'
データベースの準備
$ bin/rails generate delayed_job:active_record $ bin/rake db:migrate
ActiveJob との連携
# config/application.rb module TestApp class Application < Rails::Application : config.active_job.queue_adapter = :delayed_job end end
ワーカーの起動・停止・再起動
開発時
$ bin/rake jobs:work
本番時
# 起動 $ RAILS_ENV=production bin/delayed_job -n 2 start # 停止 $ RAILS_ENV=production bin/delayed_job -n 2 stop # 再起動 $ RAILS_ENV=production bin/delayed_job -n 2 restart
複数ワーカーを起動した時には、停止の時に-nオプションを指定する必要があるようです。(未確認ですが、バージョンによって違うようです。)
確認バージョン
- delayed_job 4.1.2
- delayed_job_active_record 4.1.1