Close
Glad You're Ready. Let's Get Started!

Let us know how we can contact you.

Thank you!

We'll respond shortly.

LABS
Nesting and authenticating resque-web on ey-cloud

Wouldn’t it be nice to include the resque-web interface underneath your current application’s url?

Wouldn’t it then be nice to use the same authentication mechanism that your web application uses?

Here’s a solution that we used on a recent Rails 2.3 ey-cloud project that accomplished both goals.

First, we created a simple resque_web.ru file within our Rails 2.3 project. In this example we used the same Warden SSO authentication mechanism and fired up the resque-web server from the new mapping.


# Set up Resque environment
resque_config = YAML.load_file(File.join(File.dirname(__FILE__), 'config', 'resque.yml'))

env = ENV['RACK_ENV'] || ENV['RAILS_ENV'] || 'development'
Resque.redis = resque_config[env]

map '/resque-web' do
  use Rack::Session::Cookie, :key => 'rack.session',
    :path => '/',
    :expire_after => 60 ** 2,
    :secret => 'supersecretresquekey'

  use CasrackTheAuthenticator::Simple, :cas_server => "http://sso.your_sso_server.com"
  use CasrackTheAuthenticator::RequireCAS
  use Rack::ShowExceptions
  run Resque::Server.new
end

The important piece here is that we use ‘/resque-web’, we’ll use this same path in a bit within our Nginx configuration. We also used the rack session cookies with our SSO authenticator.

Another interesting piece here is that we’re using Castronaut and Casrack the Authenticator, which makes SSO pretty straight forward.

Next we created an upstream server in Nginx to resolve the path. We’re just using Thin here.

Here’s our Chef template for the upstream server.


upstream resque_web_upstream {
   server unix:/var/run/engineyard/<%= @app_name %>/<%= @app_name %>.thin.1.sock;
}

The important piece here is that the upstream server lives outside of our web application config area.

Here’s our Chef recipe for creating the upstream server file.


template "/etc/nginx/servers/resque_web.conf" do
  owner "root"
  group "root"
  mode 0755
  source "resque_web.conf.erb"
  variables({
    :app_name => app_name
  })
end

And then finally, we created a new custom location within our Nginx server configuration.

Here’s our Chef template for the custom Nginx Location.


location /resque-web {
  proxy_set_header Host $http_host;
  include /etc/nginx/common/proxy.conf;
  proxy_pass http://resque_web_upstream;
}

And here’s our Chef recipe for creating the custom location file.


template "/etc/nginx/servers/#{app_name}/custom.locations.conf" do
  owner "root"
  group "root"
  mode 0755
  source "custom.locations.conf.erb"
  variables({
    :app_name => app_name
  })
end

That’s it!

Comments
  1. Rob Olson says:

    Nice! I was wondering how this might be done with Rails 2.3.

    This is really slick with Rails3 + Devise as well: http://blog.kiskolabs.com/post/776939029/rails3-resque-devise

Post a Comment

Your Information (Name required. Email address will not be displayed with comment.)

* Copy This Password *

* Type Or Paste Password Here *