From ce2cbb346554c0f3bedc6bc7223c8d6e02ef58c8 Mon Sep 17 00:00:00 2001 From: Brandur Date: Tue, 10 Jul 2012 08:52:15 -0700 Subject: [PATCH] Timeouts on all scheduled tasks --- Rakefile | 31 +++++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/Rakefile b/Rakefile index a8a6c02..77aa502 100644 --- a/Rakefile +++ b/Rakefile @@ -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