Queue Helpers for Resque

We use our own fork of Resque, Resque-Mongo which uses Mongo instead of Redis and it works extremely well.

So while going through the code looking for things that can be queued in the background we thought of a better way to push jobs than just calling:

Resque.enqueue(Category, 32)

The above code has some drawbacks:

  • You have no clue to what it’s doing unless you look at the Category.perform method.
  • If you have several different background actions on a model you end up with lots of ModelNameMethodJob classes.
  • If you want to change the method call you have a lot of refactoring to do.

It’s ruby, it should be easier right?

Yeap, and it’s only some 30 LOC (mostly cooked up by @yatiohi)

If you want to change the queuing lib or do some nice tricks for certain methods then all you have to do is change the queue method of RQueue.