Class: RightScale::CloudApi::RequestAnalyzer
- Defined in:
- lib/base/routines/request_analyzer.rb
Overview
The routine provides error_pattern method that is used to define request and response patterns.
The patterns allows one to control the request processing flow: you can enable retries for certain API calls or can re-open a connection on HTTP failure.
The supported actions are:
Request option:
-
:abort_on_timeout - If there was a low level timeout then it should not retry a request but should fail. Lets say one made a call to launch some instance and the remote cloud launched them but timed out to respond back. The default behavior for the gem is to make a retry if a timeout received but in this particular case it will launch the instances again. So the solution here is to make the system to fail after the first unsuccessfull request.
Response options:
-
:retry - Make a retry if the failed response matches to the pattern.
-
:abort - Do not make a retry and fail if the response matches to the pattern (opposite to :retry).
-
:disconnect_and_abort - Close a connection and fail.
-
:reconnect_and_retry - Reestablish a connection and make a retry.
Defined Under Namespace
Modules: ClassMethods Classes: Error
Constant Summary collapse
- REQUEST_ACTIONS =
[ :abort_on_timeout ]
- REQUEST_KEYS =
[ :verb, :verb!, :path, :path!, :request, :request!, :if ]
- RESPONSE_ACTIONS =
[ :disconnect_and_abort, :abort, :reconnect_and_retry, :retry ]
- RESPONSE_KEYS =
[ :verb, :verb!, :path, :path!, :request, :request!, :code, :code!, :response, :response!, :if ]
- ALL_ACTIONS =
REQUEST_ACTIONS + RESPONSE_ACTIONS
Instance Attribute Summary
Attributes inherited from Routine
Instance Method Summary collapse
-
#process ⇒ Object
The main entry point.
Methods inherited from Routine
#cloud_api_logger, #execute, #invoke_callback_method, #options, #reset, #with_timer
Instance Method Details
#process ⇒ Object
The main entry point.
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/base/routines/request_analyzer.rb', line 97 def process # Get a list of accessible error patterns error_patterns = data[:options][:error_patterns] || [] opts = { :request => data[:request][:instance], :response => nil, :verb => data[:request][:verb], :params => data[:request][:orig_params].dup} # Walk through all the error patterns and find the first that matches. # RequestAnalyser accepts only REQUEST_ACTIONS (actually "abort_on_timeout" only) request_error_patterns = error_patterns.select{|e| REQUEST_ACTIONS.include?(e[:action])} request_error_patterns.each do |pattern| # If we see any pattern that matches our current state if Utils::pattern_matches?(pattern, opts) # then set a flag to disable retries data[:options][:abort_on_timeout] = true cloud_api_logger.log("Request matches to error pattern: #{pattern.inspect}" , :request_analyzer) break end end end |