Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 24 additions & 14 deletions azure/durable_functions/models/DurableOrchestrationClient.py
Original file line number Diff line number Diff line change
Expand Up @@ -311,20 +311,30 @@ async def get_status_all(self) -> List[DurableOrchestrationStatus]:
"""
options = RpcManagementOptions()
request_url = options.to_url(self._orchestration_bindings.rpc_base_url)
response = await self._get_async_request(request_url)
switch_statement = {
200: lambda: None, # instance completed
}

has_error_message = switch_statement.get(
response[0],
lambda: f"The operation failed with an unexpected status code {response[0]}")
error_message = has_error_message()
if error_message:
raise Exception(error_message)
else:
statuses: List[Any] = response[1]
return [DurableOrchestrationStatus.from_json(o) for o in statuses]
all_statuses: List[DurableOrchestrationStatus] = []

continuation_token = None
while True:
headers = {}
if continuation_token:
headers['x-ms-continuation-token'] = continuation_token
response = await self._get_async_request(request_url, headers=headers)
switch_statement = {
200: lambda: None, # instance completed
}
has_error_message = switch_statement.get(
response[0],
lambda: f"The operation failed with an unexpected status code {response[0]}")
error_message = has_error_message()
if error_message:
raise Exception(error_message)
else:
statuses: List[Any] = response[1]
all_statuses.extend([DurableOrchestrationStatus.from_json(o) for o in statuses])
continuation_token = response.headers.get('x-ms-continuation-token')
if not continuation_token:
break
return all_statuses

async def get_status_by(self, created_time_from: datetime = None,
created_time_to: datetime = None,
Expand Down
8 changes: 5 additions & 3 deletions azure/durable_functions/models/utils/http_utils.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Any, List, Union
from typing import Any, List, Union, Dict, Optional

import aiohttp

Expand Down Expand Up @@ -29,20 +29,22 @@ async def post_async_request(url: str, data: Any = None) -> List[Union[int, Any]
return [response.status, data]


async def get_async_request(url: str) -> List[Any]:
async def get_async_request(url: str, headers: Dict[Any, Any] = None) -> List[Any]:
"""Get the data from the url provided.

Parameters
----------
url: str
url to get the data from
headers: Dict[str, str]
headers to send with the request

Returns
-------
[int, Any]
Tuple with the Response status code and the data returned from the request
"""
async with aiohttp.ClientSession() as session:
async with aiohttp.ClientSession(headers=headers) as session:
async with session.get(url) as response:
data = await response.json(content_type=None)
if data is None:
Expand Down