Wednesday, September 21, 2011

How To Clear Active record base Sessions.

[root@17_johnson]# cat current/lib/clear_sessions_data.rb

  require 'rubygems'
  require 'active_record'


  ActiveRecord::Base.establish_connection(
  :adapter => "mysql",
  :host => "localhost",
  :username => "root",
  :password =>"tm#secure",
  :database => "tm_production",
  :socket =>  "/var/lib/mysql/mysql.sock"
  )

 
  sql = 'DELETE FROM sessions WHERE updated_at < DATE_SUB(NOW(), INTERVAL 1 DAY);'
  ActiveRecord::Base.connection.execute(sql)

------------------
NOTE # Set script As cron at Every day 12.00 AM.

0 comments: