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
|
||||
# Configuration parameters: CountComments, CountAsOne.
|
||||
Metrics/ClassLength:
|
||||
Max: 313
|
||||
Max: 316
|
||||
|
||||
# Offense count: 58
|
||||
# Configuration parameters: IgnoredMethods.
|
||||
|
|
|
@ -231,6 +231,7 @@ class ApplicationController < ActionController::Base
|
|||
def api_call_timeout(&block)
|
||||
Timeout.timeout(Settings.api_timeout, Timeout::Error, &block)
|
||||
rescue Timeout::Error
|
||||
ActiveRecord::Base.connection.raw_connection.cancel
|
||||
raise OSM::APITimeoutError
|
||||
end
|
||||
|
||||
|
@ -243,11 +244,13 @@ class ApplicationController < ActionController::Base
|
|||
|
||||
if e.is_a?(Timeout::Error) ||
|
||||
(e.is_a?(ActiveRecord::StatementInvalid) && e.message.include?("execution expired"))
|
||||
ActiveRecord::Base.connection.raw_connection.cancel
|
||||
render :action => "timeout"
|
||||
else
|
||||
raise
|
||||
end
|
||||
rescue Timeout::Error
|
||||
ActiveRecord::Base.connection.raw_connection.cancel
|
||||
render :action => "timeout"
|
||||
end
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue