Skip to content

Instantly share code, notes, and snippets.

@johankok
Forked from yaroslav/sessions.rake
Created March 18, 2010 13:37
Show Gist options
  • Save johankok/336356 to your computer and use it in GitHub Desktop.
Save johankok/336356 to your computer and use it in GitHub Desktop.
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 = ActiveRecord::SessionStore::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