Browse files

Cron job (whenever) for deleting old request records

  • Loading branch information...
1 parent d58f322 commit 14c3d3ca61ce6b4e05d3c9f7c9cf2657eac4cd4f @winton committed Nov 7, 2010
Showing with 26 additions and 2 deletions.
  1. +5 −1 Rakefile
  2. +6 −0 config/schedule.rb
  3. +2 −1 lib/a_b/gems.rb
  4. +13 −0 tasks/cron.rake
View
6 Rakefile
@@ -83,4 +83,8 @@ task :gemspec do
end
task :package => :gemspec
-task :default => :spec
+task :default => :spec
+
+Dir[File.dirname(__FILE__) + '/tasks/*.rake'].each do |file|
+ load(file)
+end
View
6 config/schedule.rb
@@ -0,0 +1,6 @@
+set :environment, ENV['ENV'] || ENV['RACK_ENV']
+set :output, { :error => 'cron_error.log', :standard => 'cron.log' }
+
+every 1.day do
+ rake "cron:every_day"
+end
View
3 lib/a_b/gems.rb
@@ -16,13 +16,14 @@ class Gems
:rake => '=0.8.7',
:rspec => '=1.3.0',
:sinatra => '=1.0',
+ :whenever => '=0.6.2',
:with_pid => '=0.1.3'
}
TYPES = {
:console => [ :active_wrapper, :sinatra ],
:dj => [ :with_pid ],
- :gemspec => [ :active_wrapper, :haml, :json, :lilypad, :newrelic_rpm, :sinatra, :with_pid ],
+ :gemspec => [ :active_wrapper, :haml, :json, :lilypad, :newrelic_rpm, :sinatra, :whenever, :with_pid ],
:gemspec_dev => [ :cucumber, :rspec, :'rack-test' ],
:lib => [ :active_wrapper, :haml, :json, :lilypad, :newrelic_rpm, :sinatra ],
:rake => [ :active_wrapper, :rake, :rspec ],
View
13 tasks/cron.rake
@@ -0,0 +1,13 @@
+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)}'
+ SQL
+ puts "#{$db.delete(sql)} requests destroyed"
+ end
+end

0 comments on commit 14c3d3c

Please sign in to comment.