-
-
Save kares/919069 to your computer and use it in GitHub Desktop.
rake task for cleaning up ActiveRecord session store table from expired sessions
This file contains 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 :db do | |
namespace :sessions do | |
desc "Clean up expired Active Record sessions (updated before ENV['UPDATED_AT'], defaults to 1 month ago)." | |
task :expire => :environment do | |
time = Time.parse( ENV['UPDATED_AT'] || 1.month.ago.to_s(:db) ) | |
say "cleaning up expired sessions (older than #{time}) ..." | |
session = ActiveRecord::SessionStore::Session | |
rows = session.delete_all ["updated_at < ?", time] | |
say "deleted #{rows} session row(s) - there are #{session.count} session row(s) left" | |
end | |
end | |
def say(msg) | |
puts msg | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks for this. What's that
say
thing about though! Ha