Created
August 5, 2009 15:16
-
-
Save javier/162754 to your computer and use it in GitHub Desktop.
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 :mysql do | |
# Parameter 'days' indicates maximum inactivity days before deletion. Default is 30 | |
desc "cleanup old sessions from the database" | |
task :expire_sessions => :environment do | |
days = ENV['days'] || 30 | |
ActiveRecord::Base.connection.execute "delete from sessions where datediff(utc_date(),updated_at) > #{days}" | |
puts "Sessions idle more than #{days} days expired" | |
puts "Anonymous sessions expired" | |
end #task do | |
end #namespace | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment