Ruby-on-rails 如何在生产中部署 resque 工人?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1732415/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-02 21:57:54  来源:igfitidea点击:

How to deploy resque workers in production?

ruby-on-railscapistranodelayed-jobredisresque

提问by Brian Armstrong

The GitHub guys recently released their background processing app which uses Redis: http://github.com/defunkt/resquehttp://github.com/blog/542-introducing-resque

GitHub 家伙最近发布了他们使用 Redis 的后台处理应用程序:http: //github.com/defunkt/resque http://github.com/blog/542-introducing-resque

I have it working locally, but I'm struggling to get it working in production. Has anyone got a:

我让它在本地工作,但我正在努力让它在生产中工作。有没有人有:

  1. Capistrano recipe to deploy workers (control number of workers, restarting them, etc)
  2. Deployed workers to separate machine(s) from where the main app is running, what settings were needed here?
  3. gotten redis to survive a reboot on the server (I tried putting it in cron but no luck)
  4. how did you work resque-web (their excellent monitoring app) into your deploy?
  1. Capistrano 部署工人的配方(控制工人数量,重新启动他们等)
  2. 部署的工作人员将机器与主应用程序运行的地方分开,这里需要什么设置?
  3. 使 redis 在服务器上重新启动后幸存下来(我尝试将其放入 cron 但没有运气)
  4. 您是如何将 resque-web(他们出色的监控应用程序)应用到您的部署中的?

Thanks!

谢谢!

P.S. I posted an issue on Github about this but no response yet. Hoping some SO gurus can help on this one as I'm not very experienced in deployments. Thank you!

PS 我在 Github 上发布了一个关于这个的问题,但还没有回应。希望一些 SO 大师可以帮助解决这个问题,因为我在部署方面不是很有经验。谢谢!

采纳答案by Brian Armstrong

Garrett's answer really helped, just wanted to post a few more details. It took a lot of tinkering to get it right...

加勒特的回答真的很有帮助,只是想发布更多细节。花了很多功夫才把它弄对...

I'm using passenger also, but nginx instead of apache.

我也在使用乘客,但使用 nginx 而不是 apache。

First, don't forget you need to install sinatra, this threw me for a while. sudo gem install sinatra

首先,不要忘记你需要安装 sinatra,这让我有一段时间。 sudo gem install sinatra

Then you need to make a directory for the thing to run, and it has to have a public and tmp folder. They can be empty but the problem is that git won't save an empty directory in the repo. The directory has to have at least one file in it, so I made some junk files as placeholders. This is a weird feature/bug in git.

然后,您需要为要运行的东西创建一个目录,并且它必须有一个 public 和 tmp 文件夹。它们可以为空,但问题是 git 不会在 repo 中保存空目录。该目录中必须至少有一个文件,因此我制作了一些垃圾文件作为占位符。这是 git 中的一个奇怪的功能/错误。

I'm using the resque plugin, so I made the directory there (where the default config.ru is). It looks like Garrett made a new 'resque' directory in his rails_root. Either one should work. For me...

我正在使用 resque 插件,所以我在那里创建了目录(默认 config.ru 所在的位置)。看起来 Garrett 在他的 rails_root 中创建了一个新的“resque”目录。任何一个都应该工作。为了我...

cd MY_RAILS_APP/vendor/plugins/resque/
mkdir public 
mkdir tmp
touch public/placeholder.txt
touch tmp/placeholder.txt

Then I edited MY_RAILS_APP/vendor/plugins/resque/config.ruso it looks like this:

然后我编辑MY_RAILS_APP/vendor/plugins/resque/config.ru它看起来像这样:

#!/usr/bin/env ruby
require 'logger'

$LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + '/lib')
require 'resque/server'

use Rack::ShowExceptions

# Set the AUTH env variable to your basic auth password to protect Resque.
AUTH_PASSWORD = "ADD_SOME_PASSWORD_HERE"
if AUTH_PASSWORD
  Resque::Server.use Rack::Auth::Basic do |username, password|
    password == AUTH_PASSWORD
  end
end

run Resque::Server.new

Don't forget to change ADD_SOME_PASSWORD_HEREto the password you want to use to protect the app.

不要忘记更改ADD_SOME_PASSWORD_HERE您要用于保护应用程序的密码。

Finally, I'm using Nginx so here is what I added to my nginx.conf

最后,我使用 Nginx 所以这是我添加到我的 nginx.conf

server {
  listen   80;
  server_name  resque.seoaholic.com;
  root /home/admin/public_html/seoaholic/current/vendor/plugins/resque/public;
  passenger_enabled on;
}

And so it gets restarted on your deploys, probably something like this in your deploy.rb

因此它会在您的部署中重新启动,可能在您的 deploy.rb 中是这样的

run "touch #{current_path}/vendor/plugins/resque/tmp/restart.txt"

I'm not really sure if this is the best way, I've never setup rack/sinatra apps before. But it works.

我不确定这是否是最好的方法,我以前从未设置过 rack/sinatra 应用程序。但它有效。

This is just to get the monitoring app going. Next I need to figure out the god part.

这只是为了让监控应用程序运行。接下来我需要弄清楚上帝的部分。

回答by Tom Mango

I'm a little late to the party, but thought I'd post what worked for me. Essentially, I have god setup to monitor redis and resque. If they aren't running anymore, god starts them back up. Then, I have a rake task that gets run after a capistrano deploy that quits my resque workers. Once the workers are quit, god will start new workers up so that they're running the latest codebase.

我参加聚会有点晚了,但我想我会发布对我有用的东西。本质上,我有上帝设置来监视 redis 和 resque。如果它们不再运行,上帝会让它们重新启动。然后,我有一个 rake 任务,该任务在退出我的 resque 工作人员的 capistrano 部署之后运行。一旦工人退出,上帝就会启动新的工人,以便他们运行最新的代码库。

Here is my full writeup of how I use resque in production:

这是我如何在生产中使用 resque 的完整文章:

http://thomasmango.com/2010/05/27/resque-in-production

http://thomasmango.com/2010/05/27/resque-in-production

回答by Garrett

I just figured this out last night, for Capistrano you should use san_juan, then I like the use of Godto manage deployment of workers. As for surviving a reboot, I am not sure, but I reboot every 6 months so I am not too worried.

我昨晚才弄明白,对于 Capistrano 你应该使用san_juan,然后我喜欢使用God来管理工人的部署。至于能否在重启后幸存下来,我不确定,但我每 6 个月重启一次,所以我不太担心。

Although he suggest different ways of starting it, this is what worked easiest for me. (Within your deploy.rb)

尽管他提出了不同的开始方式,但对我来说这是最简单的方法。(在您的 deploy.rb 中)

require 'san_juan'
after "deploy:symlink", "god:app:reload"
after "deploy:symlink", "god:app:start"

To manage where it runs, on another server, etc, he covers that in the configuration sectionof the README.

要管理它运行,另一台服务器,等上,他介绍,在配置部分README

I use Passenger on my slice, so it was relatively easy, I just needed to have a config.rufile like so:

我在切片上使用Passenger,所以相对容易,我只需要一个config.ru像这样的文件:

require 'resque/server'

run Rack::URLMap.new \
  "/" => Resque::Server.new

For my VirtualHost file I have:

对于我的 VirtualHost 文件,我有:

<VirtualHost *:80>
        ServerName resque.server.com
        DocumentRoot /var/www/server.com/current/resque/public

        <Location />
          AuthType Basic
          AuthName "Resque Workers"
          AuthUserFile /var/www/server.com/current/resque/.htpasswd
          Require valid-user
        </Location>
</VirtualHost>

Also, a quick note. Make sure you overide the resque:setuprake task, it will save you lots of time for spawning new workers with God.

另外,一个快速说明。确保你覆盖了resque:setuprake 任务,它会为你节省大量的时间来与上帝产生新的工人。

I ran into a lot of trouble, so if you need any more help, just post a comment.

我遇到了很多麻烦,所以如果您需要更多帮助,请发表评论。

回答by Gul

Use these steps instead of making configuration with web server level and editing plugin:

使用这些步骤而不是使用 Web 服务器级别和编辑插件进行配置:

#The steps need to be performed to use resque-web with in your application

#In routes.rb

ApplicationName::Application.routes.draw do
  resources :some_controller_name
  mount Resque::Server, :at=> "/resque"
end

#That's it now you can access it from within your application i.e
#http://localhost:3000/resque

#To be insured that that Resque::Server is loaded add its requirement condition in Gemfile

gem 'resque', :require=>"resque/server"

#To add  basic http authentication add resque_auth.rb file in initializers folder and add these lines for the security

Resque::Server.use(Rack::Auth::Basic) do |user, password|
  password == "secret"
end

#That's It !!!!! :)

#Thanks to Ryan from RailsCasts for this valuable information.
#http://railscasts.com/episodes/271-resque?autoplay=true 

https://gist.github.com/1060167

https://gist.github.com/1060167