Skip to content

Instantly share code, notes, and snippets.

@maxivak
Created December 15, 2013 01:47
Show Gist options
  • Save maxivak/7967703 to your computer and use it in GitHub Desktop.
Save maxivak/7967703 to your computer and use it in GitHub Desktop.
Rails sessions: rake task to clear old sessions. Details: http://maxivak.com/rails-clear-old-sessions-stored-in-database/
namespace :sessions do
desc "Clear expired sessions (more than 3 days old)"
task :cleanup => :environment do
sql = "DELETE FROM sessions WHERE (updated_at < '#{Date.today - 3.days}')"
ActiveRecord::Base.connection.execute(sql)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment