Added total timeout of whole http request.
This commit is contained in:
parent
ead406c220
commit
5e518f5037
7 changed files with 56 additions and 16 deletions
|
@ -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?
|
||||||
|
|
|
@ -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'),
|
||||||
},
|
},
|
||||||
|
|
|
@ -7,7 +7,7 @@ class Service::GeoCalendar::Zammad
|
||||||
|
|
||||||
# check cache
|
# check cache
|
||||||
cache_key = "zammadgeocalendar::#{address}"
|
cache_key = "zammadgeocalendar::#{address}"
|
||||||
cache = Cache.get( cache_key )
|
cache = Cache.get(cache_key)
|
||||||
return cache if cache
|
return cache if cache
|
||||||
|
|
||||||
# do lookup
|
# do lookup
|
||||||
|
@ -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.$/
|
||||||
|
@ -34,10 +35,10 @@ class Service::GeoCalendar::Zammad
|
||||||
|
|
||||||
data = response.data
|
data = response.data
|
||||||
|
|
||||||
Cache.write( cache_key, data, { expires_in: 30.minutes } )
|
Cache.write(cache_key, data, { expires_in: 30.minutes })
|
||||||
rescue => e
|
rescue => e
|
||||||
Rails.logger.error "#{host}#{url}: #{e.inspect}"
|
Rails.logger.error "#{host}#{url}: #{e.inspect}"
|
||||||
Cache.write( cache_key, data, { expires_in: 1.minute } )
|
Cache.write(cache_key, data, { expires_in: 1.minute })
|
||||||
end
|
end
|
||||||
data
|
data
|
||||||
end
|
end
|
||||||
|
|
|
@ -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.$/
|
||||||
|
|
|
@ -4,10 +4,18 @@ 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)
|
||||||
|
|
||||||
return if !result
|
return if !result
|
||||||
return if !result['results']
|
return if !result['results']
|
||||||
|
@ -20,10 +28,19 @@ 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)
|
||||||
|
|
||||||
address = result['results'].first['address_components'].first['long_name']
|
address = result['results'].first['address_components'].first['long_name']
|
||||||
address
|
address
|
||||||
|
|
|
@ -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?
|
||||||
|
@ -66,7 +69,7 @@ class Service::Image::Zammad
|
||||||
return false if !image
|
return false if !image
|
||||||
|
|
||||||
# store image 1:1
|
# store image 1:1
|
||||||
product_logo = StaticAssets.store_raw( image[:content], image[:mime_type] )
|
product_logo = StaticAssets.store_raw(image[:content], image[:mime_type])
|
||||||
Setting.set('product_logo', product_logo)
|
Setting.set('product_logo', product_logo)
|
||||||
|
|
||||||
true
|
true
|
||||||
|
|
|
@ -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,
|
||||||
|
|
Loading…
Reference in a new issue