Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Cron job (whenever) for deleting old request records

  • Loading branch information...
commit 14c3d3ca61ce6b4e05d3c9f7c9cf2657eac4cd4f 1 parent d58f322
@winton authored
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
Please sign in to comment.
Something went wrong with that request. Please try again.