Michael D''Auria
2006-Sep-25  01:20 UTC
[Backgroundrb-devel] Clearing ActiveRecord Sessions
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 :.
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
http://rubyforge.org/pipermail/backgroundrb-devel/attachments/20060924/189c4e5c/attachment.html
Ezra Zygmuntowicz
2006-Sep-27  17:54 UTC
[Backgroundrb-devel] Clearing ActiveRecord Sessions
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. -Ezra