部署到生产服务器后运行延迟作业

2023-12-04

使用delayed_jobs gem(https://github.com/collectiveidea/delayed_job)在 Rails 中,我可以对我的通知进行排队。但我不太明白如何在生产服务器上运行排队的作业。我知道我可以跑

$ 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?

但我不确定这是否是正确的处理方式。谢谢


这些工作线程作为单独的进程运行,而不是作为 Rails 应用程序的一部分。最简单的方法是在screen会话以防止它在您注销终端会话时退出。但还有更好的方法:

您可以使用诸如 monit 或 God 之类的系统,或者运行delayed_job 提供的工作脚本。您可以在以下位置找到更多信息这个问题的答案.

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

部署到生产服务器后运行延迟作业 的相关文章

随机推荐