Fork me on GitHub

October 31, 2012

Resque Java

Post moved to

The title does not contain a typo, if it seems so there's likely no need to read further. It's actually about Resque - the Ruby library for creating background jobs using Redis. There's been a similar post (almost 1.5 year ago!) about bringing Delayed::Job to Java. DJ evolved since and seems to be still doing fine, Resque received a fresh breeze of activity recently and the master branch shall soon spit out a new major version.

Resque and Delayed::Job are different (although some points are not very accurate when comparing with DJ 3.x) yet serve usually the same purpose. And that is why the JRuby world should be able to run Resque workers threaded along side the (hopefully thread-safe) web application. Here's how you set it up for any Servlet container running JRuby-Rack using the Java deployment descriptor : WARNING: XML ahead!

Do not forget to copy the jruby-rack-worker.jar into your WEB-INF/lib folder or declare gem 'jruby-rack-worker' in your Gemfile and Warbler should take care of it.

It really should be stressed out that workers will run alongside your application and share resources such as memory, file descriptors with it thus you should not do this if your workers are expecting chaos and are not predictable (e.g. with memory consumption) or run jobs that take a long time to finish.

Besides, there's now a Trinidad extension and thus no excuse to keep on warbling forever, here's how a the configuration file might look like :