From: leon breedt Date: 2005-04-14T07:45:35+09:00 Subject: Re: Threads in Rails On 4/13/05, Tony Targonski wrote: > In my Rails application, I have a function perform some background > calculations inside of a thread. > > The problem is that the said thread gets no computation time unless > something else runs in parallel. If the user continuously refreshes a > page (any controller page), the function zooms through the tasks. But if > one was to just initiate the script and leave for a coffee break -- > nothing gets done. > > Threads are attention whores, how do I fix or work around that? I had a need for something similar (a long-running operation calling out to blocking OS calls). My solution was to move that out into a seperate process and use DRb to communicate the request and query for the result. At least that way, if the FastCGI dispatcher goes down for some reason, the operation is still guaranteed to complete deterministically. Supporting this kind of thing in Rails proper would start moving it towards Application Server territory :) Leon