07 February 2008

Asynchronous Tasks in Rails

On the blog Play/Type, there's a great article on how to do asynchronous tasks in a Rails app. Furthermore, they've built a Rails plugin, Workling, that encapsulates asynch tasks and provides a wrapper around Starling, Spawn, and others, making these easy to use.

I came across this tonight as I was figuring out a solution for spawning off Facebook profile FBML updates in the background since these can do a fair bit of data gathering. It is also useful in controllers used in a Facebook app, because while you never want your apps' actions to take more than 8 seconds regardless, if they do for Facebook, Facebook will simply fail to load the page. Therefore, if you have an expensive operation that can occur asynchronously, but is initiated by a controller, this is another place to leverage something like Workling.

For my own needs, I didn't wind up using Workling, as Spawn was sufficient for my needs at this time. Before I go to production, I may switch to Workling simply to provide future growth in case this Facebook app takes off, etc. This will be one to watch for sure.

0 comments: