I'm working on a Rails 2.3.x app that needs to run a long, slow task asynchronously.
开发者_运维百科Delaying the request until processing has completed is a bit of a pain. We're happy to just send a "Okay, we've received that and we're working on it"-style response back to the client, and then just crunch on the work once the client's gone away.
So I've seen a few methods for doing this (such as forking or using cron), but it seems that task queuing systems might be a better idea.
It seems like the three main ones are:
- BackgroundFu,
- BeanstalkD, and
- Sparrow
Sparrow looks particularly interesting due to it's support for Memcached, but I don't want to just pick one without making an informed decision. Does anyone have any insights regarding best practices? I'd love to hear about your experiences with the above, especially any major gotchas with this approach or the libraries mentioned. Perhaps there's an even better way to do this that I've missed completely?
Just so it's out there: Rails 3.x isn't an option right now, this needs to work for Rails 2.3.x.
Thanks!
I recommend delayed_job, specifically this fork and branch. I'm using it myself on rails 2.3.5 and it works well.
It has a rails 3 branch for when you do want to upgrade, it works with multiple backends, and it has an optional pretty syntax:
Notifier.delay.deliver_signup @user
By the way, just forking is a mistake as you'll find the fork doesn't have a good database connection.
精彩评论