0
# Polling
1
2
ARM-specific polling strategies for managing long-running operations (LROs). These polling implementations handle Azure's asynchronous operation patterns including Azure-AsyncOperation headers, location headers, and body content polling.
3
4
**Note**: The polling classes must be imported directly from their module files rather than from the `azure.mgmt.core.polling` package due to current package structure limitations.
5
6
## Capabilities
7
8
### ARMPolling
9
10
Synchronous ARM-specific long-running operation polling that combines multiple polling strategies to handle different ARM LRO patterns.
11
12
```python { .api }
13
class ARMPolling(LROBasePolling):
14
"""ARM-specific synchronous LRO polling."""
15
16
def __init__(
17
self,
18
timeout: float = 30,
19
lro_algorithms: Optional[Sequence[LongRunningOperation[HttpRequestTypeVar, AllHttpResponseTypeVar]]] = None,
20
lro_options: Optional[Dict[str, Any]] = None,
21
path_format_arguments: Optional[Dict[str, str]] = None,
22
**operation_config: Any
23
) -> None: ...
24
```
25
26
#### Default Polling Algorithms
27
28
ARMPolling uses these algorithms in order:
29
1. **AzureAsyncOperationPolling** - Handles `Azure-AsyncOperation` headers
30
2. **LocationPolling** - Handles `Location` headers
31
3. **BodyContentPolling** - Polls based on response body content
32
4. **StatusCheckPolling** - Basic status checking fallback
33
34
#### Usage Example
35
36
```python
37
from azure.mgmt.core.polling.arm_polling import ARMPolling
38
from azure.core.polling import LROPoller
39
40
# Create ARM-specific polling
41
polling = ARMPolling(timeout=60)
42
43
# Use with LROPoller
44
poller = LROPoller(
45
client=client,
46
initial_response=initial_response,
47
deserialization_callback=deserialize_func,
48
polling_method=polling
49
)
50
51
# Wait for completion
52
result = poller.result()
53
```
54
55
### AsyncARMPolling
56
57
Asynchronous ARM-specific long-running operation polling with the same polling strategies as ARMPolling but using async/await patterns.
58
59
```python { .api }
60
class AsyncARMPolling(AsyncLROBasePolling):
61
"""ARM-specific asynchronous LRO polling."""
62
63
def __init__(
64
self,
65
timeout: float = 30,
66
lro_algorithms: Optional[Sequence[LongRunningOperation[HttpRequestTypeVar, AllHttpResponseTypeVar]]] = None,
67
lro_options: Optional[Dict[str, Any]] = None,
68
path_format_arguments: Optional[Dict[str, str]] = None,
69
**operation_config: Any
70
) -> None: ...
71
```
72
73
#### Usage Example
74
75
```python
76
import asyncio
77
from azure.mgmt.core.polling.async_arm_polling import AsyncARMPolling
78
from azure.core.polling import AsyncLROPoller
79
80
async def main():
81
# Create async ARM-specific polling
82
polling = AsyncARMPolling(timeout=60)
83
84
# Use with AsyncLROPoller
85
poller = AsyncLROPoller(
86
client=client,
87
initial_response=initial_response,
88
deserialization_callback=deserialize_func,
89
polling_method=polling
90
)
91
92
# Wait for completion
93
result = await poller.result()
94
95
asyncio.run(main())
96
```
97
98
### AzureAsyncOperationPolling
99
100
Specialized polling for operations that return `Azure-AsyncOperation` headers. Handles Azure's asynchronous operation pattern with support for final-state-via options.
101
102
```python { .api }
103
class AzureAsyncOperationPolling(OperationResourcePolling[HttpRequestTypeVar, AllHttpResponseTypeVar]):
104
"""Implements a operation resource polling, typically from Azure-AsyncOperation."""
105
106
def __init__(self, lro_options: Optional[Dict[str, Any]] = None) -> None: ...
107
def get_final_get_url(self, pipeline_response: PipelineResponse[HttpRequestTypeVar, AllHttpResponseTypeVar]) -> Optional[str]: ...
108
```
109
110
#### LRO Options Support
111
112
Supports Swagger LRO options:
113
- `final-state-via: azure-async-operation` - Uses operation URL for final state
114
- `final-state-via: location` - Uses location header for final state
115
116
#### Usage Example
117
118
```python
119
from azure.mgmt.core.polling.arm_polling import AzureAsyncOperationPolling
120
121
# Configure with LRO options
122
lro_options = {"final-state-via": "azure-async-operation"}
123
polling = AzureAsyncOperationPolling(lro_options=lro_options)
124
```
125
126
### BodyContentPolling
127
128
Polling strategy that monitors the response body for provisioning state changes. Used for ARM resources that indicate their status through `properties.provisioningState`.
129
130
```python { .api }
131
class BodyContentPolling(LongRunningOperation[HttpRequestTypeVar, AllHttpResponseTypeVar]):
132
"""Poll based on the body content.
133
134
Implement a ARM resource poller (using provisioning state).
135
"""
136
137
def can_poll(self, pipeline_response: PipelineResponse[HttpRequestTypeVar, AllHttpResponseTypeVar]) -> bool: ...
138
def get_polling_url(self) -> str: ...
139
def set_initial_status(self, pipeline_response: PipelineResponse[HttpRequestTypeVar, AllHttpResponseTypeVar]) -> str: ...
140
def get_status(self, pipeline_response: PipelineResponse[HttpRequestTypeVar, AllHttpResponseTypeVar]) -> str: ...
141
```
142
143
#### Supported HTTP Methods
144
145
Only polls for requests using:
146
- `PUT` operations
147
- `PATCH` operations
148
149
#### Status Code Handling
150
151
- **202**: Returns "InProgress"
152
- **201**: Extracts provisioning state or returns "InProgress"
153
- **200**: Extracts provisioning state or returns "Succeeded"
154
- **204**: Returns "Succeeded"
155
156
#### Usage Example
157
158
```python
159
from azure.mgmt.core.polling.arm_polling import BodyContentPolling
160
161
# Usually used as part of ARMPolling, but can be used standalone
162
polling = BodyContentPolling()
163
164
# Check if this polling method can handle the response
165
if polling.can_poll(pipeline_response):
166
status = polling.get_status(pipeline_response)
167
```
168
169
## Polling Enums
170
171
### LRO Options
172
173
```python { .api }
174
class _LroOption(str, Enum, metaclass=CaseInsensitiveEnumMeta):
175
"""Known LRO options from Swagger."""
176
FINAL_STATE_VIA = "final-state-via"
177
```
178
179
### Final State Via Options
180
181
```python { .api }
182
class _FinalStateViaOption(str, Enum, metaclass=CaseInsensitiveEnumMeta):
183
"""Possible final-state-via options."""
184
AZURE_ASYNC_OPERATION_FINAL_STATE = "azure-async-operation"
185
LOCATION_FINAL_STATE = "location"
186
```
187
188
## Key Features
189
190
### Multi-Strategy Polling
191
192
ARM polling tries multiple strategies in sequence:
193
1. Check for Azure-AsyncOperation header
194
2. Check for Location header
195
3. Poll the original URL for body content changes
196
4. Fall back to basic status checking
197
198
### Provisioning State Detection
199
200
Body content polling extracts provisioning state from:
201
```json
202
{
203
"properties": {
204
"provisioningState": "Succeeded|Failed|InProgress|..."
205
}
206
}
207
```
208
209
### Timeout and Configuration
210
211
All polling methods support:
212
- Custom timeout values (default: 30 seconds)
213
- Custom polling intervals
214
- Path format arguments for URL templating
215
- Additional operation configuration
216
217
### Error Handling
218
219
- Throws `OperationFailed` for invalid initial status codes
220
- Throws `BadResponse` for empty response bodies when content is expected
221
- Proper error propagation through polling chain
222
223
## Types
224
225
```python { .api }
226
ResponseType = Union[HttpResponse, AsyncHttpResponse]
227
PipelineResponseType = PipelineResponse[HttpRequest, ResponseType]
228
HttpRequestType = Union[LegacyHttpRequest, HttpRequest]
229
AllHttpResponseType = Union[LegacyHttpResponse, HttpResponse, LegacyAsyncHttpResponse, AsyncHttpResponse]
230
HttpRequestTypeVar = TypeVar("HttpRequestTypeVar", bound=HttpRequestType)
231
AllHttpResponseTypeVar = TypeVar("AllHttpResponseTypeVar", bound=AllHttpResponseType)
232
```