Class: MsRestAzure::PollingState
- Inherits:
-
Object
- Object
- MsRestAzure::PollingState
- Defined in:
- lib/ms_rest_azure/polling_state.rb
Overview
Class which represents a state of Azure long running operation.
Instance Attribute Summary collapse
-
#azure_async_operation_header_link ⇒ String
The latest value captured from Azure-AsyncOperation header.
-
#error_data ⇒ AzureOperationError
The azure error data.
-
#location_header_link ⇒ String
The latest value captured from Location header.
-
#request ⇒ Net::HTTPRequest
The HTTP request.
-
#resource ⇒ Object
The resource.
-
#response ⇒ Net::HTTPResponse
The HTTP response.
-
#status ⇒ String
Status of the long running operation.
Instance Method Summary collapse
-
#get_delay ⇒ Integer
Returns the amount of time in seconds for long running operation polling delay.
-
#get_operation_error ⇒ AzureOperationError
Composes and returns cloud error.
-
#get_operation_response ⇒ MsRestAzure::AzureOperationResponse
returns the Azure’s response.
-
#initialize(azure_response, retry_timeout) ⇒ PollingState
constructor
A new instance of PollingState.
-
#update_response(response) ⇒ Object
Updates the polling state from the fields of given response object.
Constructor Details
#initialize(azure_response, retry_timeout) ⇒ PollingState
Returns a new instance of PollingState.
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# 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 if (!@resource.nil? && @resource.respond_to?(:properties) && @resource.properties.respond_to?(:provisioning_state) && !@resource.properties.provisioning_state.nil?) @status = @resource.properties.provisioning_state else case @response.status when 202 @status = AsyncOperationStatus::IN_PROGRESS_STATUS when 200, 201, 204 @status = AsyncOperationStatus::SUCCESS_STATUS else @status = AsyncOperationStatus::FAILED_STATUS end end end |
Instance Attribute Details
#azure_async_operation_header_link ⇒ String
Returns the latest value captured from Azure-AsyncOperation header.
24 25 26 |
# File 'lib/ms_rest_azure/polling_state.rb', line 24 def azure_async_operation_header_link @azure_async_operation_header_link end |
#error_data ⇒ AzureOperationError
Returns the azure error data.
21 22 23 |
# File 'lib/ms_rest_azure/polling_state.rb', line 21 def error_data @error_data end |
#location_header_link ⇒ String
Returns the latest value captured from Location header.
27 28 29 |
# File 'lib/ms_rest_azure/polling_state.rb', line 27 def location_header_link @location_header_link end |
#request ⇒ Net::HTTPRequest
Returns the HTTP request.
12 13 14 |
# File 'lib/ms_rest_azure/polling_state.rb', line 12 def request @request end |
#resource ⇒ Object
Returns the resource.
15 16 17 |
# File 'lib/ms_rest_azure/polling_state.rb', line 15 def resource @resource end |
#response ⇒ Net::HTTPResponse
Returns the HTTP response.
18 19 20 |
# File 'lib/ms_rest_azure/polling_state.rb', line 18 def response @response end |
#status ⇒ String
Returns status of the long running operation.
30 31 32 |
# File 'lib/ms_rest_azure/polling_state.rb', line 30 def status @status end |
Instance Method Details
#get_delay ⇒ Integer
Returns the amount of time in seconds for long running operation polling delay.
56 57 58 59 60 61 62 63 64 |
# File 'lib/ms_rest_azure/polling_state.rb', line 56 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 |
#get_operation_error ⇒ AzureOperationError
Composes and returns cloud error.
91 92 93 |
# File 'lib/ms_rest_azure/polling_state.rb', line 91 def get_operation_error AzureOperationError.new @request, @response, @error_data, "Long running operation failed with status #{@status}" end |
#get_operation_response ⇒ MsRestAzure::AzureOperationResponse
returns the Azure’s response.
82 83 84 85 |
# File 'lib/ms_rest_azure/polling_state.rb', line 82 def get_operation_response azure_response = AzureOperationResponse.new(@request, @response, @resource) azure_response end |
#update_response(response) ⇒ Object
Updates the polling state from the fields of given response object.
69 70 71 72 73 74 75 76 |
# File 'lib/ms_rest_azure/polling_state.rb', line 69 def update_response(response) @response = response if (!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 |