简体   繁体   English

如何在生产环境中自动启动Rails Background Worker

[英]How do I start my Rails Background Worker automatically in Production Environment

I figured out that I start my background worker manually on Develoment Environment. 我发现我是在Develoment Environment上手动启动后台工作人员的。

My payments/transactions will not get successful if my background worker is not running. 如果我的后台工作者没有运行,我的付款/交易将不会成功。

What I have done 我做了什么

I created a Procfile and inside it I have the following such that I this below: 我创建了一个Procfile,并在其中包含以下内容:

ApplicationName/Procfile ApplicationName /程序文件

worker: bundle exec rake jobs:work 

Will this actually solve my problem if I deploy my application? 如果部署我的应用程序,这是否真的可以解决我的问题? And if not, how do I start background worker on Production? 如果没有, 我该如何在生产中启动后台工作者?

Update 更新资料

I have been called to order from posted answers the Procfile works only for Heroku . 我被要求从发布的答案中订购,Procfile仅适用于Heroku Note that I like to deploy to DigitalOcean . 请注意, 我喜欢部署到DigitalOcean I am using Delayed_Job for my Background Worker, and inside its documentation, it states that we can use the following code on production with the help of bundling "daemons" gem with it. 我正在为我的Background Worker使用Delayed_Job,在它的文档中,它声明我们可以在生产中使用以下代码,将其与"daemons" gem捆绑在一起。

RAILS_ENV=production script/delayed_job start
RAILS_ENV=production script/delayed_job stop

Is there anyway I can automate this by initilizing it, such that env. 无论如何,我可以通过初始化它来自动化它,例如env。 pick up the code to execute? 拿起代码执行?

Procfile will work only for heroku. Procfile仅适用于heroku。 So skip the rest of my answer if you are deploying to Heroku. 因此,如果您要部署到Heroku,请跳过我的其余回答。

How to do it depends on system you are deploying. 如何执行取决于您所部署的系统。 Most of the modern linux systems (ie Ubuntu) using systemd. 大多数使用systemd的现代linux系统(即Ubuntu)。 So you very likely need to create startup script and put it to /lib/systemd/system/__your_service__.service 因此,您很可能需要创建启动脚本并将其放入/lib/systemd/system/__your_service__.service

Just for example 举个例子

[Unit]
Description=__Your worker_name__

[Service]
Type=forking
User=__your_user__
WorkingDirectory=__your_working_dir__
Environment=RAILS_ENV=production
PIDFile=__your_working_dir__/tmp/pids/__your_service__.pid
ExecStart=absolute_path_to_bundle exec rake jobs:work 

[Install]
WantedBy=multi-user.target

And afterwards type and you are good :) 然后键入,你就很好了:)

sudo systemctl enable __your_service__ && sudo systemctl start __your_service__

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Rails 4 - 如何优化Heroku生产环境? - Rails 4 - How do I optimize my Heroku production environment? 如何在生产环境中运行Rails发电机? - How do I run a rails generator in a production environment? 如何在Rails的生产环境中添加pg gem? - How do I ADD the pg gem in the production environment in Rails 如何在生产后台启动Foreman Server? - How do I start Foreman server on background on production? 如何测试生产环境而不是测试环境Rails - How can I test my production environment instead of my test environment Rails 当我的rails应用程序加载时,如何自动启动sphinx守护程序? - How do I start the sphinx daemon automatically when my rails application loads? 我在这个开发环境中有背景图片,但在生产环境中没有 - rails I have a background image in development environment this show but not in production 如何轻松重组尚未投入生产的 Rails 数据库? - How do I easily restructure my Rails' DB not yet in production? 我如何告诉我的rails程序在生产中运行? - How do i tell my rails program to run on production? 如何更改刚刚部署到生产中的应用程序的Rails环境? - How do I change the rails environment an app I just deployed to production?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM