如何在生产环境中运行delayed_jobs

How to run delayed_jobs in production environment

我在 rails 应用程序开发中使用 delayed_job,在开发环境中我使用 bin/delayed_job start

但是如何在生产环境中做同样的事情呢?

RAILS_ENV=production bin/delayed_job start

这应该使生产环境中的延迟作业 运行

开始:

cd /home/user/app;
bundle exec /usr/bin/env RAILS_ENV=production /home/user/app/script/delayed_job start

停止:

cd /home/user/app; 
bundle exec /usr/bin/env RAILS_ENV=production /home/user/app/script/delayed_job stop

请参阅 github 上的官方文档。

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

# Use the --pool option to specify a worker pool. You can use this option multiple times to start different numbers of workers for different queues.
# The following command will start 1 worker for the tracking queue,
# 2 workers for the mailers and tasks queues, and 2 workers for any jobs:
RAILS_ENV=production script/delayed_job --pool=tracking --pool=mailers,tasks:2 --pool=*:2 start

# Runs all available jobs and then 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

如果其他人遇到 -bash: bin/delayed_job: Permission denied 错误,就像 Disha 在上面的评论中所做的那样,对于 Centos,在 bin/ 中设置 delayed_job 就足够了项目目录中的文件夹到可执行文件。