[Backgroundrb-devel] Clearing ActiveRecord Sessions

Ezra Zygmuntowicz ezmobius at gmail.com
Wed Sep 27 13:54:24 EDT 2006

On Sep 24, 2006, at 6:20 PM, Michael D'Auria wrote:

> Hello all,
> I am interested in using BackgrounDRb to clear out ActiveRecord  
> based sessions.  I have this working, just with a small hitch, here  
> is the code:
> class ClearSessionsWorker < BackgrounDRb::Rails
>   repeat_every 7.minutes
>   first_run Time.now
>   def do_work(args)
>     Session.destroy_all(["updated_at < ?", 20.minute.ago ])
>   end
> end
> It's not very complicated and does remove sessions, it's just that  
> once the job is done, the thread hangs out leaving a connection to  
> my database open.  After some time, MySQL complains about having  
> too many open connections.  I was just curious what i am missing.   
> I have tried using "kill", but that only seems to run the job once  
> and not every 7 minutes like i so nicely ask :).  I have also tried  
> "terminate", but that did not seem to do anything for me.  Any help  
> is greatly appreciated.
> Thanks,
> .: Michael :.

Hi Michael-

	Yeah you need to call ActiveRecord::Base.connection.disconect!  in  
your worker when it is done working. I am hard at work on a new  
version of the plugin that is a totaly new beast. I hope to release  
it soon but I am super busy these days. The new version has a much  
more robust timing mechanism and everything else.


More information about the Backgroundrb-devel mailing list