So at Hashrocket, we’ve been deploying a number of apps to Engine Yard Cloud. Some of these apps have required the use of background jobs. A library that facilitates that is called Resque. Once set up1, it has a Sinatra web app you can use to monitor the queue’s progress. To make a long story short, it isn’t trivial to setup Resque Web on Engine Yard Cloud. This is what we did to make it work:
In your environment.rb add the following line:
1 Rails::Initializer.run do |config| 2 #[...] 3 config.middleware.use 'ResqueWeb' 4 end
Then create a library under RAILS_ROOT/lib/resque_web.rb with the following:
1 require 'sinatra/base' 2 class ResqueWeb < Sinatra::Base 3 require 'resque/server' 4 use Rack::ShowExceptions 5 def call(env) 6 if env["PATH_INFO"] =~ /^\/resque/ 7 env["PATH_INFO"].sub!(/^\/resque/, '') 8 env['SCRIPT_NAME'] = '/resque' 9 app = Resque::Server.new 10 app.call(env) 11 else 12 super 13 end 14 end 15 end
That’s it. Deploy your app to staging to test it and boom!
1 This assumes you already have Resque installed in your EY Cloud app.