Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 970
Christian Fazzini Avatar asked Aug 31 '11 13:08

Christian Fazzini


2 Answers

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.

like image 144
Maurício Linhares Avatar answered Sep 27 '22 22:09

Maurício Linhares


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.

like image 23
Max Wallace Avatar answered Sep 27 '22 23:09

Max Wallace