Skip to content

Commit

Permalink
Timeouts on all scheduled tasks
Browse files Browse the repository at this point in the history
  • Loading branch information
brandur committed Jul 10, 2012
1 parent 1cde209 commit ce2cbb3
Showing 1 changed file with 23 additions and 8 deletions.
31 changes: 23 additions & 8 deletions Rakefile
Expand Up @@ -2,31 +2,46 @@
# Add your own tasks in files placed in lib/tasks ending in .rake,
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.

require 'timeout'

require File.expand_path('../config/application', __FILE__)

Dorian::Application.load_tasks

desc 'Expires everything so that pages show fresher timestamps'
task :expire => :environment do
# use timeouts in here specifically because occasionally memcache takes a very
# long time to respond and starts eating task time (i.e. dyno-hours)

def clear_cache
Slides.log :cache_clear do
Rails.cache.clear
Timeout.timeout(1) do
begin
Rails.cache.clear
rescue
$stderr.puts "error message=#{$!.message}"
end
end
end
end

desc 'Expires everything so that pages show fresher timestamps'
task :expire => :environment do
clear_cache
end

desc 'Update data from source for all modules (e.g. Goodreads, Twitter, etc.)'
task :update => :environment do
Slides.log :update do
App.module_instances do |mod|
Slides.log :update, module: mod.class.name do
begin
mod.update
Timeout.timeout(10) do
mod.update
end
rescue
$stderr.puts "update_error module=#{mod.class.name} message=#{$!.message}"
$stderr.puts "error module=#{mod.class.name} message=#{$!.message}"
end
end
end
Slides.log :cache_clear do
Rails.cache.clear
end
clear_cache
end
end

0 comments on commit ce2cbb3

Please sign in to comment.