class MsRestAzure::PollingState
Class which represents a state of Azure long running operation.
Attributes
@return [String] the latest value captured from Azure-AsyncOperation header.
@return [AzureOperationError] the azure error data.
@return [String] the latest value captured from Location header.
@return [Net::HTTPRequest] the HTTP request.
@return the resource
@return [Net::HTTPResponse] the HTTP response.
@return [Integer] retry timeout.
@return [String] status of the long running operation.
Public Class Methods
# File lib/ms_rest_azure/polling_state.rb, line 32 def initialize(azure_response, retry_timeout) @retry_timeout = retry_timeout @request = azure_response.request update_response(azure_response.response) @resource = azure_response.body case @response.status when 200 provisioning_state = get_provisioning_state @status = provisioning_state.nil?? (AsyncOperationStatus::SUCCESS_STATUS):provisioning_state when 201 provisioning_state = get_provisioning_state @status = provisioning_state.nil?? (AsyncOperationStatus::IN_PROGRESS_STATUS):provisioning_state when 202 @status = AsyncOperationStatus::IN_PROGRESS_STATUS when 204 @status = AsyncOperationStatus::SUCCESS_STATUS else @status = AsyncOperationStatus::FAILED_STATUS end end
Public Instance Methods
Returns the amount of time in seconds for long running operation polling delay.
@return [Integer] Amount of time in seconds for long running operation polling delay.
# File lib/ms_rest_azure/polling_state.rb, line 74 def get_delay return @retry_timeout unless @retry_timeout.nil? if !response.nil? && !response.headers['Retry-After'].nil? return response.headers['Retry-After'].to_i end return AsyncOperationStatus::DEFAULT_DELAY end
Composes and returns cloud error.
@return [AzureOperationError] the cloud error.
# File lib/ms_rest_azure/polling_state.rb, line 109 def get_operation_error AzureOperationError.new @request, @response, @error_data, "Long running operation failed with status #{@status}" end
returns the Azure's response.
@return [MsRestAzure::AzureOperationResponse] Azure's response.
# File lib/ms_rest_azure/polling_state.rb, line 100 def get_operation_response azure_response = AzureOperationResponse.new(@request, @response, @resource) azure_response end
Returns the provisioning status of the resource
@return [String] provisioning status of the resource
# File lib/ms_rest_azure/polling_state.rb, line 58 def get_provisioning_state # On non flattened resource, we should find provisioning_state inside 'properties' if (!@resource.nil? && @resource.respond_to?(:properties) && @resource.properties.respond_to?(:provisioning_state) && !@resource.properties.provisioning_state.nil?) @resource.properties.provisioning_state # On flattened resource, we should find provisioning_state at the top level elsif !@resource.nil? && @resource.respond_to?(:provisioning_state) && !@resource.provisioning_state.nil? @resource.provisioning_state else nil end end
# File lib/ms_rest_azure/polling_state.rb, line 113 def get_request(options = {}) link = @azure_async_operation_header_link || @location_header_link options[:connection] = create_connection(options[:base_uri]) MsRest::HttpOperationRequest.new(nil, link, :get, options) end
Updates the polling state from the fields of given response object. @param response [Net::HTTPResponse] the HTTP response.
# File lib/ms_rest_azure/polling_state.rb, line 87 def update_response(response) @response = response unless response.nil? @azure_async_operation_header_link = response.headers['Azure-AsyncOperation'] unless response.headers['Azure-AsyncOperation'].nil? @location_header_link = response.headers['Location'] unless response.headers['Location'].nil? end end
Private Instance Methods
# File lib/ms_rest_azure/polling_state.rb, line 126 def create_connection(base_url) @connection ||= Faraday.new(:url => base_url, :ssl => MsRest.ssl_options) do |faraday| [[MsRest::RetryPolicyMiddleware, times: 3, retry: 0.02], [:cookie_jar]].each{ |args| faraday.use(*args) } faraday.adapter Faraday.default_adapter faraday.headers = request.headers logging = ENV['AZURE_HTTP_LOGGING'] || request.log if logging faraday.response :logger, nil, { :bodies => logging == 'full' } end end end