Permalink
Browse files

Cron job (whenever) for deleting old request records

  • Loading branch information...
1 parent d77ffcc commit 8969a907f8180590c68bb0c44b134908f61a83da @winton committed Nov 8, 2010
Showing with 9 additions and 1 deletion.
  1. +9 −1 tasks/cron.rake
View
@@ -3,11 +3,19 @@ namespace :cron do
desc 'Every day cron job'
task :every_day => :environment do
$db.establish_connection
+
sql = <<-SQL
DELETE
FROM requests
- WHERE updated_at < '#{1.day.ago.utc.to_s(:sql)}'
+ WHERE updated_at < #{$db.quote 1.day.ago.utc}
SQL
puts "#{$db.delete(sql)} requests destroyed"
+
+ sql = <<-SQL
+ DELETE
+ FROM ips
+ WHERE `date` < #{$db.quote 1.day.ago.utc}
+ SQL
+ puts "#{$db.delete(sql)} ips destroyed"
end
end

0 comments on commit 8969a90

Please sign in to comment.