Added total timeout of whole http request.

This commit is contained in:
Martin Edenhofer 2016-01-21 02:07:50 +01:00
parent ead406c220
commit 5e518f5037
7 changed files with 56 additions and 16 deletions

View file

@ -111,6 +111,7 @@ add a avatar
{ {
open_timeout: 4, open_timeout: 4,
read_timeout: 6, read_timeout: 6,
total_timeout: 6,
}, },
) )
if !response.success? if !response.success?

View file

@ -60,6 +60,7 @@ module Import::OTRS
{ {
open_timeout: 10, open_timeout: 10,
read_timeout: 60, read_timeout: 60,
total_timeout: 180,
user: Setting.get('import_otrs_user'), user: Setting.get('import_otrs_user'),
password: Setting.get('import_otrs_password'), password: Setting.get('import_otrs_password'),
}, },
@ -93,9 +94,11 @@ module Import::OTRS
log 'PARAMS: ' + data.inspect log 'PARAMS: ' + data.inspect
open_timeout = 10 open_timeout = 10
read_timeout = 120 read_timeout = 120
total_timeout = 360
if data.empty? if data.empty?
open_timeout = 6 open_timeout = 6
read_timeout = 20 read_timeout = 20
total_timeout = 120
end end
response = UserAgent.post( response = UserAgent.post(
url, url,
@ -103,6 +106,7 @@ module Import::OTRS
{ {
open_timeout: open_timeout, open_timeout: open_timeout,
read_timeout: read_timeout, read_timeout: read_timeout,
total_timeout: total_timeout,
user: Setting.get('import_otrs_user'), user: Setting.get('import_otrs_user'),
password: Setting.get('import_otrs_password'), password: Setting.get('import_otrs_password'),
}, },

View file

@ -26,6 +26,7 @@ class Service::GeoCalendar::Zammad
json: true, json: true,
open_timeout: 2, open_timeout: 2,
read_timeout: 4, read_timeout: 4,
total_timeout: 12,
}, },
) )
if !response.success? && response.code.to_s !~ /^40.$/ if !response.success? && response.code.to_s !~ /^40.$/

View file

@ -22,6 +22,7 @@ class Service::GeoIp::Zammad
json: true, json: true,
open_timeout: 2, open_timeout: 2,
read_timeout: 4, read_timeout: 4,
total_timeout: 4,
}, },
) )
if !response.success? && response.code.to_s !~ /^40.$/ if !response.success? && response.code.to_s !~ /^40.$/

View file

@ -4,7 +4,15 @@ class Service::GeoLocation::Gmaps
def self.geocode(address) def self.geocode(address)
url = "http://maps.googleapis.com/maps/api/geocode/json?address=#{CGI.escape address}&sensor=true" url = "http://maps.googleapis.com/maps/api/geocode/json?address=#{CGI.escape address}&sensor=true"
response = UserAgent.get(url) response = UserAgent.get(
url,
{},
{
open_timeout: 2,
read_timeout: 4,
total_timeout: 4,
},
)
return if !response.success? return if !response.success?
result = JSON.parse(response.body) result = JSON.parse(response.body)
@ -20,7 +28,16 @@ class Service::GeoLocation::Gmaps
def self.reverse_geocode(lat, lng) def self.reverse_geocode(lat, lng)
url = "http://maps.googleapis.com/maps/api/geocode/json?latlng=#{lat},#{lng}&sensor=true" url = "http://maps.googleapis.com/maps/api/geocode/json?latlng=#{lat},#{lng}&sensor=true"
response = UserAgent.get(url) response = UserAgent.get(
url,
{},
{
json: true,
open_timeout: 2,
read_timeout: 4,
total_timeout: 4,
},
)
return if !response.success? return if !response.success?
result = JSON.parse(response.body) result = JSON.parse(response.body)

View file

@ -6,6 +6,7 @@ class Service::Image::Zammad
@@api_host = 'https://images.zammad.com' @@api_host = 'https://images.zammad.com'
@@open_timeout = 4 @@open_timeout = 4
@@read_timeout = 6 @@read_timeout = 6
@@total_timeout = 8
def self.user(email) def self.user(email)
@ -18,6 +19,7 @@ class Service::Image::Zammad
{ {
open_timeout: @@open_timeout, open_timeout: @@open_timeout,
read_timeout: @@read_timeout, read_timeout: @@read_timeout,
total_timeout: @@total_timeout,
}, },
) )
if !response.success? if !response.success?
@ -46,6 +48,7 @@ class Service::Image::Zammad
{ {
open_timeout: @@open_timeout, open_timeout: @@open_timeout,
read_timeout: @@read_timeout, read_timeout: @@read_timeout,
total_timeout: @@total_timeout,
}, },
) )
if !response.success? if !response.success?

View file

@ -59,8 +59,11 @@ returns
# start http call # start http call
begin begin
total_timeout = options[:total_timeout] || 60
Timeout.timeout(total_timeout) do
response = http.request(request) response = http.request(request)
return process(response, uri, count, params, options) return process(response, uri, count, params, options)
end
rescue => e rescue => e
return Result.new( return Result.new(
error: e.inspect, error: e.inspect,
@ -83,6 +86,7 @@ post http/https calls
{ {
open_timeout: 4, open_timeout: 4,
read_timeout: 10, read_timeout: 10,
total_timeout: 60,
}, },
) )
@ -107,8 +111,11 @@ returns
# start http call # start http call
begin begin
total_timeout = options[:total_timeout] || 60
Timeout.timeout(total_timeout) do
response = http.request(request) response = http.request(request)
return process(response, uri, count, params, options) return process(response, uri, count, params, options)
end
rescue => e rescue => e
return Result.new( return Result.new(
error: e.inspect, error: e.inspect,
@ -155,8 +162,11 @@ returns
# start http call # start http call
begin begin
total_timeout = options[:total_timeout] || 60
Timeout.timeout(total_timeout) do
response = http.request(request) response = http.request(request)
return process(response, uri, count, params, options) return process(response, uri, count, params, options)
end
rescue => e rescue => e
return Result.new( return Result.new(
error: e.inspect, error: e.inspect,
@ -196,8 +206,11 @@ returns
# start http call # start http call
begin begin
total_timeout = options[:total_timeout] || 60
Timeout.timeout(total_timeout) do
response = http.request(request) response = http.request(request)
return process(response, uri, count, {}, options) return process(response, uri, count, {}, options)
end
rescue => e rescue => e
return Result.new( return Result.new(
error: e.inspect, error: e.inspect,