Search code examples
ruby-on-rails-3herokuresque

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/server'

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?


Solution

  • 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.