在生产服务器上部署后运行延迟的作业 [英] Run delayed jobs after deployed on production server

查看:77
本文介绍了在生产服务器上部署后运行延迟的作业的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在delays_jobs gem( https://github.com/collectiveidea/delayed_job )中,我可以将通知排队。但是我不太了解如何在生产服务器上运行排队的作业。我知道我可以跑步

With the delayed_jobs gem(https://github.com/collectiveidea/delayed_job) in rails, I am able to queue my notifications. But I don't quite understand how can I run the queued jobs on the production server. I knew I can just run

$ rake jobs:work

在本地服务器的控制台中。如文档所述,
然后可以执行以下操作:

in the console for the local server. As the documentation said, You can then do the following:

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应用程序集成?我在考虑在其中创建一个名为delay_jobs.rb的文件。配置/初始化为:

My question is how to integrate it with my Rails app?I was thinking to create a file called delayed_jobs.rb in config/initializers as:

# in config/initializers/delayed_jobs
script/delayed_job start if Rails.env.production?

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

But I am not sure if it is the right way to do with it. Thanks

推荐答案

工作程序作为单独的进程运行,而不是作为Rails应用程序的一部分运行。最简单的方法是在 screen 会话中运行rake任务以防止其退出当您退出终端会话时。但是还有更好的方法:

The workers run as separate processes, not as part of your Rails application. The simplest way would be to run the rake task in a screen session to prevent it from quitting when you log out of the terminal session. But there are better ways:

您将使用monit或God之类的系统,或者运行delay_job提供的worker脚本。您可以在此问题的答案中找到更多信息。

You would use a system such as monit or God or run the worker script provided by delayed_job. You'll find more information in the answers to this question.

这篇关于在生产服务器上部署后运行延迟的作业的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆