Skip to content

Instantly share code, notes, and snippets.

@digitalpardoe
Created July 16, 2011 21:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save digitalpardoe/1086790 to your computer and use it in GitHub Desktop.
Save digitalpardoe/1086790 to your computer and use it in GitHub Desktop.
Clearing Out Old Sessions
Session.destroy_all("created_at" < (Time.now - 1.day))
0 0 * * * cd /home/user/railsapp && rake RAILS_ENV=production session:prune > /dev/null 2>&1
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