Sunday, August 01, 2010

Running Resque Web

Today, I finally dove into Rack. Whenever I hear about a new technology, I know what it is, but don't have anything specific in mind, so I never end up playing with it. Until I have to--which is both good and bad. Good in that I never end up wasting time with dead-end technologies. Bad in that I could have solved other problems with this tool had I known about it more in depth.

I wanted to run resque's resque-web along-side of the Noteleaf app. It's basically a simple sinatra app that tells you the current state of the background workers. After reading about it for a while, I found different solutions. , and .

The one on stackoverflow suggested that you write write your own Btw, you put in your Rails root directory. No one seems to mention that. After a lot of reading I came up with the rather vanilla:

However, when deploying it to the server, rackup didn't seem to be able to find my rails gem. So looking around some more, I did find another hint on engineyard, when lead me to find this:

1 2 3 4 do |config|
  config.middleware.use 'ResqueWeb'

You edit your config/environments.rb file like so, and resque_web.rb can either be required in your environments file or put in the initializers, where it's loaded before environments is.

In hindsight, that works well, because it's a small demo of how to insert your own middleware into rails. And it's not that hard either. Just have to look up the rack calls, and environment variables, so you'll know what's available. 

Finally having something concrete for using Rack is great. I had been thinking about a host of other stuff that's considered the underbelly of a web app that can be better implemented as Rack middleware apps, rather than contaminating your web app itself. Neato.

Posted via email from The Web and all that Jazz

No comments:

Post a Comment