2011-07-13 25 views
6

我有一个简单的Rails应用程序部署到Heroku Cedar堆栈。Heroku Cedar - 没有用于装载Resque前端的静态资产

应用程序使用Resque和Resque西纳特拉前端应用程序安装,所以我可以监控队列:

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

这个伟大的工程,但在部署到Heroku上,该Resque front-end's 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 

我怎样才能得到它为这些资产?

回答

6

尝试删除路线并在您的config.ru中安装应用程序。我使用的线沿线的东西:

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

run Rack::URLMap.new(
    "/" => Rails.application, 
    "/resque" => Resque::Server.new 
) 
+0

谢谢ezki,作品一种享受。 – zefer

+2

不适合我。 – Simpleton

0

我认为在部署到heroku时需要设置根路径。例如,我在config.ru指定

require './app' 
run ExampleApp 

,并设置根app.rb从而引导西纳特拉应用:

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

这解决了在西纳特拉的应用程序没有提供与静态资产的问题,为了我。 对于resque,也许你可以扩展类,然后挂载它,设置根目录?

+0

感谢tiredpixel,很高兴知道这个未来的选择。 – zefer

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 
+1

谢谢凯恩,很好的建议。然而,我决定保留在我的resque.rb初始化程序中定义的身份验证,如下所示: '#在resque前端使用基本身份验证 Resque :: Server.use(Rack :: Auth :: Basic)做|用户,密码| 密码==“secret” end' – zefer

0

的Heroku雪松堆栈和救援需要这行代码,以防止数据库连接失败。

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" 

希望这可以帮助别人,因为它为我做了尽可能多的。