From: Tom Hughes Date: Mon, 11 Jan 2010 09:28:31 +0000 (+0000) Subject: Use system_timer for timeouts to make them more reliable. X-Git-Tag: live~6343^2~22 X-Git-Url: https://git.openstreetmap.org/rails.git/commitdiff_plain/841ebe80d7e62068e8c2813bbeb82ecfbfeb0607 Use system_timer for timeouts to make them more reliable. --- diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 479f24525..53ad1e901 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -208,9 +208,11 @@ class ApplicationController < ActionController::Base end def api_call_timeout - Timeout::timeout(APP_CONFIG['api_timeout'], OSM::APITimeoutError) do + SystemTimer.timeout_after(APP_CONFIG['api_timeout']) do yield end + rescue Timeout::Error + raise OSM::APITimeoutError end ## diff --git a/app/controllers/browse_controller.rb b/app/controllers/browse_controller.rb index 96cec3943..5c7912d15 100644 --- a/app/controllers/browse_controller.rb +++ b/app/controllers/browse_controller.rb @@ -81,7 +81,7 @@ class BrowseController < ApplicationController private def timeout - Timeout::timeout(30) do + SystemTimer.timeout_after(30) do yield end rescue Timeout::Error diff --git a/config/environment.rb b/config/environment.rb index 4493d07a4..727ab2d46 100644 --- a/config/environment.rb +++ b/config/environment.rb @@ -52,6 +52,7 @@ Rails::Initializer.run do |config| config.gem 'rmagick', :lib => 'RMagick' config.gem 'oauth', :version => '>= 0.3.6' config.gem 'httpclient' + config.gem 'system_timer' # Only load the plugins named here, in the order given. By default, all plugins # in vendor/plugins are loaded in alphabetical order.