开发者

How to get resque-web to work on Heroku?

On my dev machine, I am able to type resque-web in a console and it launches a new tab on my browser which shows the Resque interface.

On Heroku, Cedar stack, how can I do the same thing? i.e. I would like to see Resque's interface for my Heroku app.

EDIT

in config/initializers/resque.rb

require 'resque'
require 'resque/se开发者_运维知识库rver'

uri = URI.parse(APP_CONFIG['redis_to_go_url'])
Resque.redis = Redis.new(:host => uri.host, :port => uri.port, :password => uri.password)

# Load all jobs at /app/jobs
Dir["#{Rails.root}/app/jobs/*.rb"].each { |file| require file }

in routes.rb

mount Resque::Server.new, :at => '/resque'

Everything works. I am now able to see the Resque web interface. However, I would like to protect this from public view. Possibly with a username and password. How can this be done?


I don't really know heroku, but if you have a config.ru or Rackup file you can run resque-web inside your own rails app, here's a sample of how to do it:

require File.dirname(__FILE__) + '/config/environment'
require 'resque/server'

Resque::Server.class_eval do

  use Rack::Auth::Basic do |email, password|
    user = User.authenticate( email, password )
    user && user.admin?
  end

end

app = Rack::Builder.new {
  use Rails::Rack::Static

  map "/resque" do
    run Resque::Server
  end

  map "/" do
    run ActionController::Dispatcher.new
  end
}.to_app

run app

EDIT

As you are already mounting it inside of rails, just add this statement in an initializer file:

Resque::Server.class_eval do

  use Rack::Auth::Basic do |email, password|
    user = User.authenticate( email, password )
    user && user.admin?
  end

end

Obviously, make User.authenticate( email, password ) whatever you use to authenticate your users.


This question and Maurício's answer are likely referring to the Sinatra app included with Resque.

There's also resque-web, a Rails Engine that can be added to an existing Rails app on Heroku. I found this to be an easier and faster solution.

Resque-web includes an interface for HTTP basic auth, which you can check out in the project documentation.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜