ãã¼ã¿ãã¼ã¹ã®ã»ãã·ã§ã³ãã¼ã¿ãåé¤ãã
Railsã§ã»ãã·ã§ã³ããã¼ã¿ãã¼ã¹ã«æ ¼ç´ããã®ã¯ãããã話ã¨æ³ãã®ã ãã©ãããã®ããããªæé¤ã®ä»æ¹ä»ãè¦å½ãããªãã£ãã®ã§ãã¡ãã£ã¨ã¡ã¢
ãã¤ãéãç°å¢ã¯ããã®ã¨ãã
- Rails2.1.2
- Ruby1.8.6 P287
configã«æ¸ãã¦ããSessionãDatabaseã«æ ¼ç´ããå®ç¾©ã¯ä»¥ä¸ã®éãã
config.action_controller.session_store = :active_record_store
Rakeã§åé¤ããæ©è½ãæ¢ãã¦ã¿ãã¨ä»¥ä¸ã®ç©ããã£ã
#rake db:sessions:clear
ãããRAILS_ROOTã§èµ·åããã¨ç¢ºãã«ãã¼ã¿ãã¼ã¹ä¸ã®ã»ãã·ã§ã³æ å ±ã¯æ¶ããã®ã ãã©ãããã¯ããããã£ã±ãæ¶ãã¦ãã¾ããæ¥ç¶ä¸ã ãããä½ã ãããæ¶ãã¦ãã¾ãã®ã§ããã¯æ²ããã
ãããã§ä¸å®æéããå¤ããã®ãæ¶ãããã®ã ãã©ãã©ãããã®ããã¾ãã®ãããããããªãã以ä¸ã®ãããªç©ãä½ã£ã¦ã¿ãã
#mkdir RAILS_ROOT/crons #touch delsession.rb
ãã®ãã¡ã¤ã«ã®ä¸ã«ã¯ä»¥ä¸ã®ãããªæãã§æ¸ãã
@target_days = 3 #æå®æ¥ä»ããåã®ã»ãã·ã§ã³ãåé¤ãã #ã»ãã·ã§ã³ã®ã¢ãã«ãå®£è¨ class Session < ActiveRecord::Base end #ã»ãã·ã§ã³åé¤ Session.delete_all(["updated_at<?",(Time.new - @target_days.days)])
ãã¨ã¯ããããå®æçã«å¼ã¹ã°ããã®ã§é©å½ãªã·ã§ã«ãã¡ã¤ã«ãä½ã£ã¦ã¿ãã
#!/bin/bash cd RAILS_ROOT #ããã¯ç°å¢ã«å¿ãã¦æ¸ãæãã /usr/local/bin/ruby ./script/runner 'eval(IO.readlines("./crons/delsession.rb").join)'
ããã§å®æçã«åé¤å¦çãå®è¡åºæ¥ãããããæ£ããåããªã®ãã©ããªã®ãããããããªããã©ãç®çã¯éããããããªæãã