Skip to content

Instantly share code, notes, and snippets.

@xarimanx
Forked from kares/sessions.rake
Created April 2, 2014 06:01
Show Gist options
  • Save xarimanx/9928687 to your computer and use it in GitHub Desktop.
Save xarimanx/9928687 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['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