Last active
September 3, 2015 23:05
-
-
Save ches/225746 to your computer and use it in GitHub Desktop.
Use mysql to expire sessions without loading the Rails environment, so we can call this task from cron without it being unnecessarily expensive.
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
usage = <<DESC | |
Use mysql to expire sessions without loading the Rails environment, so we | |
can call this task from cron without it being unnecessarily expensive. | |
Takes path to Rails app and desired RAILS_ENV as arguments. | |
DESC | |
namespace :db do | |
namespace :sessions do | |
desc usage | |
task :expire, :app_path, :rails_env do |task, args| | |
conf = YAML.load_file(File.join(args.app_path, 'config', 'database.yml'))[args.rails_env.to_s] | |
sh %!mysql -u#{conf['username']} -p#{conf['password']} -e 'DELETE FROM sessions WHERE DATEDIFF(NOW(),updated_at) > 14;' #{conf['database']}! | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment