dinshaw gobhai
2006-Jul-07 19:27 UTC
[Rails] Cronjob / .rb help clearing session table (new to cronjobs)
I just launched my first ROR app and i need to implement the session database cleanup. I am new to cronjobs. I have used one once but it was all copy/paste. I was hoping someone knew of a good tutorial or resource to get started here or might be able to give me a little help. I have seen a lot of posts that reference setting a cron job to clear old sessions but I am not clear on: Can you put the script in the crontask? If not, should the .rb live anywhere (/username/) or does it have to be in one of the cron directories (houly/daiily/etc)? Or can you just run straight SQL out of the crontab (that seems like it would be the most efficient)? I saw the "ruby script/runner" reference in a couple of posts. Is this some other way of solving this problem? Are there a few ways to solve this problem? Would anyone mind telling me which is the best one? My guess, at this point, is that i set the cronjob to run a standalone .rb that does something like Session.find(:all, :conditions => ["updated_at <= ?",date_to_delete_from]).destroy Anyway, i think it is clear that I am confused any help or even a little direction would be greatly appreciated. Thanks -- Posted via http://www.ruby-forum.com/.
Al Evans
2006-Jul-07 23:35 UTC
[Rails] Re: Cronjob / .rb help clearing session table (new to cronjo
dinshaw gobhai wrote:> Are there a few ways to solve this problem? Would anyone mind telling me > which is the best one?My favorite way is to use SessionCleanup. (Well, duh, I wrote it!:-) Basically, you put it in your lib directory, and call it from some convenient place in one of your controllers where an extra second or two every few hours won''t be noticed. You set the interval at which it runs and how long it should keep sessions before deleting them. You can have it pass the session hash for each session being deleted to a block, in case there are external workfiles or whatever associated with the sessions. You can get SessionCleanup here: http://www.alevans.com/dl/session_cleanup-0.3.0.tgz Hope this helps! --Al Evans -- Posted via http://www.ruby-forum.com/.