From 4f304e23018e9a1380e2374b9a8d419275d99c76 Mon Sep 17 00:00:00 2001 From: Andy Allan Date: Wed, 23 Dec 2020 14:25:58 +0000 Subject: [PATCH] Remove SystemTimer and use stdlib Timeout directly SystemTimer was only needed on ruby 1.8, and we dropped support for that a long time ago. --- .rubocop_todo.yml | 2 +- Gemfile | 3 --- Gemfile.lock | 2 -- app/controllers/api/amf_controller.rb | 4 +++- app/controllers/application_controller.rb | 6 ++++-- lib/nominatim.rb | 4 +++- lib/osm.rb | 7 ------- 7 files changed, 11 insertions(+), 17 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index c1060cbe23..890fcc83cb 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -58,7 +58,7 @@ Metrics/BlockNesting: # Offense count: 25 # Configuration parameters: CountComments, CountAsOne. Metrics/ClassLength: - Max: 643 + Max: 644 # Offense count: 68 # Configuration parameters: IgnoredMethods. diff --git a/Gemfile b/Gemfile index 8869fb37cf..264674fbcb 100644 --- a/Gemfile +++ b/Gemfile @@ -88,9 +88,6 @@ gem "libxml-ruby", ">= 2.0.5", :require => "libxml" gem "htmlentities" gem "sanitize" -# Load SystemTimer for implementing request timeouts -gem "SystemTimer", ">= 1.1.3", :require => "system_timer", :platforms => :ruby_18 - # Load faraday for mockable HTTP client gem "faraday" diff --git a/Gemfile.lock b/Gemfile.lock index 4a9e2e042f..b4c92abdff 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,7 +1,6 @@ GEM remote: https://rubygems.org/ specs: - SystemTimer (1.2.3) aasm (5.1.1) concurrent-ruby (~> 1.0) actioncable (6.0.3.4) @@ -468,7 +467,6 @@ PLATFORMS ruby DEPENDENCIES - SystemTimer (>= 1.1.3) aasm actionpack-page_caching (>= 1.2.0) active_record_union diff --git a/app/controllers/api/amf_controller.rb b/app/controllers/api/amf_controller.rb index 5d45eb0704..34a8ff7f14 100644 --- a/app/controllers/api/amf_controller.rb +++ b/app/controllers/api/amf_controller.rb @@ -37,6 +37,8 @@ module Api class AmfController < ApiController + require "timeout" + include Potlatch before_action :check_api_writable @@ -130,7 +132,7 @@ def amf_handle_error(call, rootobj, rootid) def amf_handle_error_with_timeout(call, rootobj, rootid, &block) amf_handle_error(call, rootobj, rootid) do - OSM::Timer.timeout(Settings.api_timeout, OSM::APITimeoutError, &block) + Timeout.timeout(Settings.api_timeout, OSM::APITimeoutError, &block) end end diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 9f2d79eaa7..586b181165 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -1,4 +1,6 @@ class ApplicationController < ActionController::Base + require "timeout" + include SessionPersistence protect_from_forgery :with => :exception @@ -229,7 +231,7 @@ def assert_method(method) ## # wrap an api call in a timeout def api_call_timeout(&block) - OSM::Timer.timeout(Settings.api_timeout, Timeout::Error, &block) + Timeout.timeout(Settings.api_timeout, Timeout::Error, &block) rescue Timeout::Error raise OSM::APITimeoutError end @@ -237,7 +239,7 @@ def api_call_timeout(&block) ## # wrap a web page in a timeout def web_timeout(&block) - OSM::Timer.timeout(Settings.web_timeout, Timeout::Error, &block) + Timeout.timeout(Settings.web_timeout, Timeout::Error, &block) rescue ActionView::Template::Error => e e = e.cause diff --git a/lib/nominatim.rb b/lib/nominatim.rb index ffa86d93fe..fd0855fc9e 100644 --- a/lib/nominatim.rb +++ b/lib/nominatim.rb @@ -1,4 +1,6 @@ module Nominatim + require "timeout" + extend ActionView::Helpers::NumberHelper def self.describe_location(lat, lon, zoom = nil, language = nil) @@ -9,7 +11,7 @@ def self.describe_location(lat, lon, zoom = nil, language = nil) url = "https://nominatim.openstreetmap.org/reverse?lat=#{lat}&lon=#{lon}&zoom=#{zoom}&accept-language=#{language}" begin - response = OSM::Timer.timeout(4) do + response = Timeout.timeout(4) do REXML::Document.new(Net::HTTP.get(URI.parse(url))) end rescue StandardError diff --git a/lib/osm.rb b/lib/osm.rb index a6d7406777..51e98f4aea 100644 --- a/lib/osm.rb +++ b/lib/osm.rb @@ -5,13 +5,6 @@ module OSM require "rexml/text" require "xml/libxml" - if defined?(SystemTimer) - Timer = SystemTimer - else - require "timeout" - Timer = Timeout - end - # The base class for API Errors. class APIError < RuntimeError def initialize(message = "Generic API Error")