使用 script/delayed_job 进行生产 - 您的 capistrano 部署将在推送新代码后调用以下命令
RAILS_ENV=production script/delayed_job stop
RAILS_ENV=production script/delayed_job start
笔记
Rails 4:用 bin/delayed_job 替换 script/delayed_job
通常在开发中,我会在“进程中”执行作业,但是当我想模拟生产时,可以选择指定一个环境变量来运行
见https://github.com/collectiveidea/delayed_job#gory-details - config/initializers/delayed_job_config.rb
# execute job synch during tests and dev
# or pass arg for async in those environments
delayed_execution = if ENV['DELAY_JOBS']
true
else
!(Rails.env.test? or Rails.env.development?)
end
Delayed::Worker.delay_jobs = delayed_execution
那么如果你想在开发中运行延迟单独的进程启动两个轨道和作业进程 - 请注意延迟的作业不会自动加载更改,你必须每次重新启动它
$ DELAY_JOBS=true rails s
$ DELAY_JOBS=true bundle exec rake jobs:work