Cancel running queries when a timeout occurs
This commit is contained in:
parent
4677b58d33
commit
09263bc4a1
2 changed files with 4 additions and 1 deletions
|
@ -60,7 +60,7 @@ Metrics/BlockNesting:
|
||||||
# Offense count: 25
|
# Offense count: 25
|
||||||
# Configuration parameters: CountComments, CountAsOne.
|
# Configuration parameters: CountComments, CountAsOne.
|
||||||
Metrics/ClassLength:
|
Metrics/ClassLength:
|
||||||
Max: 313
|
Max: 316
|
||||||
|
|
||||||
# Offense count: 58
|
# Offense count: 58
|
||||||
# Configuration parameters: IgnoredMethods.
|
# Configuration parameters: IgnoredMethods.
|
||||||
|
|
|
@ -231,6 +231,7 @@ class ApplicationController < ActionController::Base
|
||||||
def api_call_timeout(&block)
|
def api_call_timeout(&block)
|
||||||
Timeout.timeout(Settings.api_timeout, Timeout::Error, &block)
|
Timeout.timeout(Settings.api_timeout, Timeout::Error, &block)
|
||||||
rescue Timeout::Error
|
rescue Timeout::Error
|
||||||
|
ActiveRecord::Base.connection.raw_connection.cancel
|
||||||
raise OSM::APITimeoutError
|
raise OSM::APITimeoutError
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -243,11 +244,13 @@ class ApplicationController < ActionController::Base
|
||||||
|
|
||||||
if e.is_a?(Timeout::Error) ||
|
if e.is_a?(Timeout::Error) ||
|
||||||
(e.is_a?(ActiveRecord::StatementInvalid) && e.message.include?("execution expired"))
|
(e.is_a?(ActiveRecord::StatementInvalid) && e.message.include?("execution expired"))
|
||||||
|
ActiveRecord::Base.connection.raw_connection.cancel
|
||||||
render :action => "timeout"
|
render :action => "timeout"
|
||||||
else
|
else
|
||||||
raise
|
raise
|
||||||
end
|
end
|
||||||
rescue Timeout::Error
|
rescue Timeout::Error
|
||||||
|
ActiveRecord::Base.connection.raw_connection.cancel
|
||||||
render :action => "timeout"
|
render :action => "timeout"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue