Created
November 2, 2008 19:16
-
-
Save yaroslav/21733 to your computer and use it in GitHub Desktop.
Rake task for Ruby on Rails for cleaning up ActiveRecord session store table from expired sessions. A bit lame (talk about logger.info not working in production) but still.
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['EXPIRE_AT'], defaults to 1 month ago)." | |
task :expire => :environment do | |
Rails.logger.info "Cleaning up expired sessions..." | |
puts "Cleaning up expired sessions..." | |
time = ENV['EXPIRE_AT'] || 1.month.ago.to_s(:db) | |
rows = CGI::Session::ActiveRecordStore::Session.delete_all ["updated_at < ?", time] | |
Rails.logger.info "Expired sessions cleanup: #{rows} session row(s) deleted." | |
puts "Expired sessions cleanup: #{rows} session row(s) deleted." | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment