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.
This commit is contained in:
parent
279787943e
commit
4f304e2301
7 changed files with 11 additions and 17 deletions
|
@ -58,7 +58,7 @@ Metrics/BlockNesting:
|
||||||
# Offense count: 25
|
# Offense count: 25
|
||||||
# Configuration parameters: CountComments, CountAsOne.
|
# Configuration parameters: CountComments, CountAsOne.
|
||||||
Metrics/ClassLength:
|
Metrics/ClassLength:
|
||||||
Max: 643
|
Max: 644
|
||||||
|
|
||||||
# Offense count: 68
|
# Offense count: 68
|
||||||
# Configuration parameters: IgnoredMethods.
|
# Configuration parameters: IgnoredMethods.
|
||||||
|
|
3
Gemfile
3
Gemfile
|
@ -88,9 +88,6 @@ gem "libxml-ruby", ">= 2.0.5", :require => "libxml"
|
||||||
gem "htmlentities"
|
gem "htmlentities"
|
||||||
gem "sanitize"
|
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
|
# Load faraday for mockable HTTP client
|
||||||
gem "faraday"
|
gem "faraday"
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
GEM
|
GEM
|
||||||
remote: https://rubygems.org/
|
remote: https://rubygems.org/
|
||||||
specs:
|
specs:
|
||||||
SystemTimer (1.2.3)
|
|
||||||
aasm (5.1.1)
|
aasm (5.1.1)
|
||||||
concurrent-ruby (~> 1.0)
|
concurrent-ruby (~> 1.0)
|
||||||
actioncable (6.0.3.4)
|
actioncable (6.0.3.4)
|
||||||
|
@ -468,7 +467,6 @@ PLATFORMS
|
||||||
ruby
|
ruby
|
||||||
|
|
||||||
DEPENDENCIES
|
DEPENDENCIES
|
||||||
SystemTimer (>= 1.1.3)
|
|
||||||
aasm
|
aasm
|
||||||
actionpack-page_caching (>= 1.2.0)
|
actionpack-page_caching (>= 1.2.0)
|
||||||
active_record_union
|
active_record_union
|
||||||
|
|
|
@ -37,6 +37,8 @@
|
||||||
|
|
||||||
module Api
|
module Api
|
||||||
class AmfController < ApiController
|
class AmfController < ApiController
|
||||||
|
require "timeout"
|
||||||
|
|
||||||
include Potlatch
|
include Potlatch
|
||||||
|
|
||||||
before_action :check_api_writable
|
before_action :check_api_writable
|
||||||
|
@ -130,7 +132,7 @@ module Api
|
||||||
|
|
||||||
def amf_handle_error_with_timeout(call, rootobj, rootid, &block)
|
def amf_handle_error_with_timeout(call, rootobj, rootid, &block)
|
||||||
amf_handle_error(call, rootobj, rootid) do
|
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
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,6 @@
|
||||||
class ApplicationController < ActionController::Base
|
class ApplicationController < ActionController::Base
|
||||||
|
require "timeout"
|
||||||
|
|
||||||
include SessionPersistence
|
include SessionPersistence
|
||||||
|
|
||||||
protect_from_forgery :with => :exception
|
protect_from_forgery :with => :exception
|
||||||
|
@ -229,7 +231,7 @@ class ApplicationController < ActionController::Base
|
||||||
##
|
##
|
||||||
# wrap an api call in a timeout
|
# wrap an api call in a timeout
|
||||||
def api_call_timeout(&block)
|
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
|
rescue Timeout::Error
|
||||||
raise OSM::APITimeoutError
|
raise OSM::APITimeoutError
|
||||||
end
|
end
|
||||||
|
@ -237,7 +239,7 @@ class ApplicationController < ActionController::Base
|
||||||
##
|
##
|
||||||
# wrap a web page in a timeout
|
# wrap a web page in a timeout
|
||||||
def web_timeout(&block)
|
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
|
rescue ActionView::Template::Error => e
|
||||||
e = e.cause
|
e = e.cause
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,6 @@
|
||||||
module Nominatim
|
module Nominatim
|
||||||
|
require "timeout"
|
||||||
|
|
||||||
extend ActionView::Helpers::NumberHelper
|
extend ActionView::Helpers::NumberHelper
|
||||||
|
|
||||||
def self.describe_location(lat, lon, zoom = nil, language = nil)
|
def self.describe_location(lat, lon, zoom = nil, language = nil)
|
||||||
|
@ -9,7 +11,7 @@ module Nominatim
|
||||||
url = "https://nominatim.openstreetmap.org/reverse?lat=#{lat}&lon=#{lon}&zoom=#{zoom}&accept-language=#{language}"
|
url = "https://nominatim.openstreetmap.org/reverse?lat=#{lat}&lon=#{lon}&zoom=#{zoom}&accept-language=#{language}"
|
||||||
|
|
||||||
begin
|
begin
|
||||||
response = OSM::Timer.timeout(4) do
|
response = Timeout.timeout(4) do
|
||||||
REXML::Document.new(Net::HTTP.get(URI.parse(url)))
|
REXML::Document.new(Net::HTTP.get(URI.parse(url)))
|
||||||
end
|
end
|
||||||
rescue StandardError
|
rescue StandardError
|
||||||
|
|
|
@ -5,13 +5,6 @@ module OSM
|
||||||
require "rexml/text"
|
require "rexml/text"
|
||||||
require "xml/libxml"
|
require "xml/libxml"
|
||||||
|
|
||||||
if defined?(SystemTimer)
|
|
||||||
Timer = SystemTimer
|
|
||||||
else
|
|
||||||
require "timeout"
|
|
||||||
Timer = Timeout
|
|
||||||
end
|
|
||||||
|
|
||||||
# The base class for API Errors.
|
# The base class for API Errors.
|
||||||
class APIError < RuntimeError
|
class APIError < RuntimeError
|
||||||
def initialize(message = "Generic API Error")
|
def initialize(message = "Generic API Error")
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue