6

我有一个简单的 Rails 应用程序部署到 Heroku Cedar 堆栈。

该应用程序使用 Resque 并安装了 Resque Sinatra 前端应用程序,因此我可以监控队列:

# routes.rb
...
mount Resque::Server, :at => "/resque"

这很好用,但是当部署到 Heroku 时,没有提供Resque 前端的 CSS 和 JavaScript

Heroku 的日志片段表明它返回零字节:

...
2011-07-13T16:19:35+00:00 heroku[router]: GET myapp.herokuapp.com/resque/style.css dyno=web.1 queue=0 wait=0ms service=3ms status=200 bytes=0
2011-07-13T16:19:35+00:00 app[web.1]: 
2011-07-13T16:19:35+00:00 app[web.1]: 
2011-07-13T16:19:35+00:00 app[web.1]: Started GET "/resque/style.css" for 87.xx.xx.xx at 2011-07-13 16:19:35 +0000
2011-07-13T16:19:35+00:00 app[web.1]: cache: [GET /resque/style.css] miss

我怎样才能让它为这些资产服务?

4

4 回答 4

6

尝试删除路线并将应用程序安装在您的config.ru. 我正在使用以下内容:

require ::File.expand_path('../config/environment',  __FILE__)
require 'resque/server'

run Rack::URLMap.new(
    "/" => Rails.application,
    "/resque" => Resque::Server.new 
)
于 2011-07-13T22:51:38.770 回答
5

与 ezkl 相同,但受密码保护,适用于我:

# config.ru
# This file is used by Rack-based servers to start the application.

require ::File.expand_path('../config/environment',  __FILE__)
require 'resque/server'

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

run Rack::URLMap.new \
  '/'       => MyApp::Application,
  '/resque' => Resque::Server.new
于 2011-07-14T03:14:20.347 回答
0

HEROKU Cedar 堆栈和救援需要这行代码来防止数据库连接失败。

Resque.after_fork = Proc.new { ActiveRecord::Base.establish_connection }

上面的代码应该放在:/lib/tasks/resque.rake

例如:

require 'resque/tasks'

task "resque:setup" => :environment do
  ENV['QUEUE'] = '*'

  Resque.after_fork do |job|
    ActiveRecord::Base.establish_connection
  end

end

desc "Alias for resque:work (To run workers on Heroku)"
task "jobs:work" => "resque:work"

希望这对某人有所帮助,就像对我一样。

于 2012-03-06T16:30:12.330 回答
0

我认为在部署到 heroku 时有必要设置根路径。例如,我通过指定启动 sinatra 应用程序

require './app'
run ExampleApp

in config.ru,并因此设置根app.rb

class ExampleApp < Sinatra::Base
  set :root, File.dirname(__FILE__)
end

对我来说,这解决了静态资产未在 sinatra 应用程序中提供服务的问题。对于 resque,也许您可​​以扩展类并安装它,设置根目录?

于 2011-07-13T21:38:15.117 回答