I know there''s a one-liner that will remove ActiveRecord sessions older than a certain date. I''d like to run a daily cron job to keep the collection relatively low. Can someone please remind me? Thanks -- View this message in context: http://www.nabble.com/AR-Session-Tidying-tf2902806.html#a8110254 Sent from the RubyOnRails Users mailing list archive at Nabble.com. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Steve Ross wrote:> I know there''s a one-liner that will remove ActiveRecord sessions older > than > a certain date. I''d like to run a daily cron job to keep the collection > relatively low. Can someone please remind me?I run this via backgroundrb, but you should be able to run it via script/runner: MINUTES_TO_KEEP = <whatever> c = CGI::Session::ActiveRecordStore::Session.delete_all( [''updated_at < ?'', MINUTES_TO_KEEP.minutes.ago ] ) --Al Evans -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
> I''d like to run a daily cron job to keep the collection > relatively low. Can someone please remind me?This crontab entry works for me: @daily /path/to/myapp/script/runner ''CGI::Session::ActiveRecordStore::Session.destroy_all( ["updated_at < ?", 1.day.ago ] )'' -e production --Victor Grey -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
I came up with a slightly different solution: I wrote a simple plugin. The idea is that I need to do this in most of my Rails apps, so having a crontab entry: @daily /wherever/my/current/script/runner "Session.cleanup" The cleanup method takes an optional argument of as-of, so I can do: script/runner "Session.cleanup(10.minutes.ago)" Is the plugin worth posting? Steve Al Evans-2 wrote:> > > Steve Ross wrote: >> I know there''s a one-liner that will remove ActiveRecord sessions older >> than >> a certain date. I''d like to run a daily cron job to keep the collection >> relatively low. Can someone please remind me? > > I run this via backgroundrb, but you should be able to run it via > script/runner: > > MINUTES_TO_KEEP = <whatever> > c = CGI::Session::ActiveRecordStore::Session.delete_all( [''updated_at < > ?'', MINUTES_TO_KEEP.minutes.ago ] ) > > --Al Evans > > -- > Posted via http://www.ruby-forum.com/. > > > > >-- View this message in context: http://www.nabble.com/AR-Session-Tidying-tf2902806.html#a8110948 Sent from the RubyOnRails Users mailing list archive at Nabble.com. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---