Created
July 16, 2011 21:06
-
-
Save digitalpardoe/1086790 to your computer and use it in GitHub Desktop.
Clearing Out Old Sessions
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Session.destroy_all("created_at" < (Time.now - 1.day)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
0 0 * * * cd /home/user/railsapp && rake RAILS_ENV=production session:prune > /dev/null 2>&1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace :session do | |
desc "Prune old session data" | |
task :prune => :environment do | |
sql = ActiveRecord::Base.connection() | |
sql.execute "SET autocommit=0" | |
sql.begin_db_transaction | |
response = sql.execute("DELETE FROM sessions WHERE `updated_at` < DATE_SUB(CURDATE(), INTERVAL 1 DAY)"); | |
sql.commit_db_transaction | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment