Skip to content

Instantly share code, notes, and snippets.

@amaia
Created May 21, 2009 13:58
Show Gist options
  • Save amaia/115476 to your computer and use it in GitHub Desktop.
Save amaia/115476 to your computer and use it in GitHub Desktop.
Rake task to delete old sessions from database (Rails).
# metodo antiguo
desc "Delete old sessions from database."
task :delete_old_sessions => :environment do
#puts "Removing old sessions from #{ENV['RAILS_ENV']} database" unless ENV['SILENT']
sesiones = CGI::Session::ActiveRecordStore::Session.find(:all, :conditions => ['updated_at < ?', 3.hours.ago])
sesiones.each {|s| s.destroy }
end
# para rails 2.3.5
desc "Borrar de la base de datos la sesiones que han expirado ."
task :borrar_sesiones => :environment do
sesiones = ActiveRecord::SessionStore::Session.find(:all, :conditions => ['updated_at < ?', 3.hours.ago])
sesiones.each {|s| s.delete}
sesiones2 = ActiveRecord::SessionStore::Session.find(:all, :conditions => ['created_at < ?', 10.day.ago])
sesiones2.each {|s| s.delete}
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment