jemnotesversion 2 / featuring this entry or see all/search

Feb 1
It seems that getting multi-threaded processes working nicely in rails is quite hard. You can’t just use a ruby thread—you’ll have all sorts of problems with classes being unloaded behind your back, and weird failures for models to be adjusted in the background. Here are some pages about it:
  • Threading in rails, an article from August 2007 which describes some problems the author was having, which sound very similar to mine.
  • A new version of the above article from February 2009, which talks about some of the problems he had with the first approach.
  • Spawn, which describes the module I ended up using.
  • BackgrounDRb, which has awful capitalization in its name, but is an alternative approach for running background jobs. This moves it outside the main process, and is more involved an approach than I wanted.
  • delayed_job, an alternative to BackgrounDRb.
Good luck getting threading working how you want it in rails. In my case, I’ve installed the spawn plugin using
script/plugin install git://github.com/tra/spawn.git
and then I have
spawn do
  # job running in the background
end
which seems to be working for now. Phew.