Class: MsRestAzure::PollingState

Inherits:
Object
  • Object
show all
Defined in:
lib/ms_rest_azure/polling_state.rb

Overview

Class which represents a state of Azure long running operation.

Instance Attribute Summary collapse

Instance Method Summary collapse

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

Returns the latest value captured from Azure-AsyncOperation header.

Returns:

  • (String)

    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_dataAzureOperationError

Returns the azure error data.

Returns:



21
22
23
# File 'lib/ms_rest_azure/polling_state.rb', line 21

def error_data
  @error_data
end

Returns the latest value captured from Location header.

Returns:

  • (String)

    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

#requestNet::HTTPRequest

Returns the HTTP request.

Returns:

  • (Net::HTTPRequest)

    the HTTP request.



12
13
14
# File 'lib/ms_rest_azure/polling_state.rb', line 12

def request
  @request
end

#resourceObject

Returns the resource.

Returns:

  • the resource



15
16
17
# File 'lib/ms_rest_azure/polling_state.rb', line 15

def resource
  @resource
end

#responseNet::HTTPResponse

Returns the HTTP response.

Returns:

  • (Net::HTTPResponse)

    the HTTP response.



18
19
20
# File 'lib/ms_rest_azure/polling_state.rb', line 18

def response
  @response
end

#statusString

Returns status of the long running operation.

Returns:

  • (String)

    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_delayInteger

Returns the amount of time in seconds for long running operation polling delay.

Returns:

  • (Integer)

    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_errorAzureOperationError

Composes and returns cloud error.

Returns:



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_responseMsRestAzure::AzureOperationResponse

returns the Azure’s response.

Returns:



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.

Parameters:

  • response (Net::HTTPResponse)

    the HTTP response.



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