使用rails 中的delayed_jobs gem(https://github.com/collectiveidea/delayed_job),我可以将我的通知排队。但我不太明白如何在生产服务器上运行排队的作业。我知道我可以跑
$ rake jobs:work
在本地服务器的控制台中。如文档所述,您可以执行以下操作:
RAILS_ENV=production script/delayed_job start
RAILS_ENV=production script/delayed_job stop
# Runs two workers in separate processes.
RAILS_ENV=production script/delayed_job -n 2 start
RAILS_ENV=production script/delayed_job stop
# Set the --queue or --queues option to work from a particular queue.
RAILS_ENV=production script/delayed_job --queue=tracking start
RAILS_ENV=production script/delayed_job --queues=mailers,tasks start
# Runs all available jobs and the exits
RAILS_ENV=production script/delayed_job start --exit-on-complete
# or to run in the foreground
RAILS_ENV=production script/delayed_job run --exit-on-complete
我的问题是如何将它与我的 Rails 应用程序集成?我想在 config/initializers 中创建一个名为delayed_jobs.rb 的文件:
# in config/initializers/delayed_jobs
script/delayed_job start if Rails.env.production?
但我不确定这是否是正确的方法。谢谢