[英]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.