[Backgroundrb-devel] [Rails] [ANN] BackgrounDRb New release.

Ezra Zygmuntowicz ezmobius at gmail.com
Mon Jul 3 22:10:21 EDT 2006


On Jul 3, 2006, at 5:36 PM, hemant wrote:

> Yeah looks fine.
>
> BTW, you didn't tell me abt, what happens to the session object,  
> when after 30 minutes that thread gets deleted?
>
>

Hemant-

	Ok after thinking about things this is what it in the current svn. I  
think you are right to wonder about what to do with a stale session.  
So I changed things to behave like this:

When you do:
session[:job_key] = MiddleMan.new_worker(:class => :long_worker,
                                                                         
           :args => 'whatever')


It will create an immortal worker by default if you don't include  
the :ttl param. But you can include the :ttl if you want to be specific.

#So this will create an immortal worker too:
session[:job_key] = MiddleMan.new_worker(:class => :long_worker,
                                                                         
          :args => 'whatever',
                                                                         
          :ttl => :immortal)

So now you have to specify the :ttl param if you want your worker to  
be killed after a certain amount of time.

session[:job_key] = MiddleMan.new_worker(:class => :long_worker,
                                                                         
          :args => 'whatever',
                                                                         
          :ttl => 900) # 15 minutes

When you create immortal workers you are responsible for deleting  
them when you are done. When you do use caching you still get a  
default :ttl of 10 minutes. And you should use the block form of  
cache_get so that if the cache has expired, it will get filled again  
and behave like a cache hit.

So to answer your question about what to do with the session if your  
worker dies is something like this:

unless MiddleMan[session[:jobkey]].nil?
    MiddleMan[session[:jobkey]].some_method
end

So I recommend either using immortal workers and deleting them with  
delete_worker or being careful about checking that your job is alive  
before calling methods on it.


Cheers-
-Ezra



More information about the Backgroundrb-devel mailing list