Skip to content

Commit 20d00e7

Browse files
cgillumCopilot
andcommitted
Add instance_id_prefix support to get_status_by
Adds an optional instance_id_prefix parameter to RpcManagementOptions and DurableOrchestrationClient.get_status_by, emitting it as the instanceIdPrefix query string parameter on the management URL. This brings the Python SDK to parity with the .NET SDKs and the underlying Durable Task extension HTTP API. Fixes #601 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 5b4465b commit 20d00e7

4 files changed

Lines changed: 32 additions & 3 deletions

File tree

azure/durable_functions/models/DurableOrchestrationClient.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,8 @@ async def get_status_all(self) -> List[DurableOrchestrationStatus]:
354354

355355
async def get_status_by(self, created_time_from: datetime = None,
356356
created_time_to: datetime = None,
357-
runtime_status: List[OrchestrationRuntimeStatus] = None) \
357+
runtime_status: List[OrchestrationRuntimeStatus] = None,
358+
instance_id_prefix: str = None) \
358359
-> List[DurableOrchestrationStatus]:
359360
"""Get the status of all orchestration instances that match the specified conditions.
360361
@@ -367,6 +368,8 @@ async def get_status_by(self, created_time_from: datetime = None,
367368
runtime_status: List[OrchestrationRuntimeStatus]
368369
Return orchestration instances which match any of the runtimeStatus values
369370
in this list.
371+
instance_id_prefix: str
372+
Return orchestration instances whose instance ID starts with this prefix.
370373
371374
Returns
372375
-------
@@ -376,7 +379,8 @@ async def get_status_by(self, created_time_from: datetime = None,
376379
# TODO: do we really want folks to us this without specifying all the args?
377380
options = RpcManagementOptions(created_time_from=created_time_from,
378381
created_time_to=created_time_to,
379-
runtime_status=runtime_status)
382+
runtime_status=runtime_status,
383+
instance_id_prefix=instance_id_prefix)
380384
request_url = options.to_url(self._orchestration_bindings.rpc_base_url)
381385
response = await self._get_async_request(request_url)
382386
switch_statement = {

azure/durable_functions/models/RpcManagementOptions.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ def __init__(self, instance_id: str = None, task_hub_name: str = None,
1616
created_time_to: datetime = None,
1717
runtime_status: List[OrchestrationRuntimeStatus] = None, show_input: bool = None,
1818
operation_name: str = None,
19-
entity_Id: EntityId = None):
19+
entity_Id: EntityId = None,
20+
instance_id_prefix: str = None):
2021
self._instance_id = instance_id
2122
self._task_hub_name = task_hub_name
2223
self._connection_name = connection_name
@@ -28,6 +29,7 @@ def __init__(self, instance_id: str = None, task_hub_name: str = None,
2829
self._show_input = show_input
2930
self.operation_name = operation_name
3031
self.entity_Id = entity_Id
32+
self._instance_id_prefix = instance_id_prefix
3133

3234
@staticmethod
3335
def _add_arg(query: List[str], name: str, value: Any):
@@ -76,6 +78,7 @@ def to_url(self, base_url: Optional[str]) -> str:
7678
self._add_date_arg(query, 'createdTimeFrom', self._created_time_from)
7779
self._add_date_arg(query, 'createdTimeTo', self._created_time_to)
7880
self._add_arg(query, 'op', self.operation_name)
81+
self._add_arg(query, 'instanceIdPrefix', self._instance_id_prefix)
7982
if self._runtime_status is not None and len(self._runtime_status) > 0:
8083
runtime_status = ",".join(r.value for r in self._runtime_status)
8184
self._add_arg(query, 'runtimeStatus', runtime_status)

tests/models/test_DurableOrchestrationClient.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,21 @@ async def test_get_500_get_status_by_failed(binding_string):
285285
await client.get_status_by(runtime_status=[OrchestrationRuntimeStatus.Running])
286286

287287

288+
@pytest.mark.asyncio
289+
async def test_get_200_get_status_by_with_instance_id_prefix(binding_string):
290+
mock_request = MockRequest(
291+
expected_url=f"{RPC_BASE_URL}instances/?instanceIdPrefix=940c5f519eb0",
292+
response=[200, [dict(createdTime=TEST_CREATED_TIME,
293+
lastUpdatedTime=TEST_LAST_UPDATED_TIME,
294+
runtimeStatus="Running")]])
295+
client = DurableOrchestrationClient(binding_string)
296+
client._get_async_request = mock_request.get
297+
298+
result = await client.get_status_by(instance_id_prefix="940c5f519eb0")
299+
assert result is not None
300+
assert len(result) == 1
301+
302+
288303
@pytest.mark.asyncio
289304
async def test_get_200_get_status_all_success(binding_string):
290305
mock_request = MockRequest(expected_url=f"{RPC_BASE_URL}instances/",

tests/models/test_RpcManagementOptions.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,5 +75,12 @@ def test_datetime_status():
7575
to_as_string = created_time_to.strftime(DATETIME_STRING_FORMAT)
7676
expected = f"{RPC_BASE_URL}instances/?createdTimeFrom={from_as_string}" \
7777
f"&createdTimeTo={to_as_string}"
78+
assert_urls_match(expected=expected, result=result)
79+
80+
81+
def test_instance_id_prefix():
82+
options = RpcManagementOptions(instance_id_prefix='940c5f519eb0')
83+
result = options.to_url(RPC_BASE_URL)
84+
expected = f"{RPC_BASE_URL}instances/?instanceIdPrefix=940c5f519eb0"
7885

7986
assert_urls_match(expected=expected, result=result)

0 commit comments

Comments
 (0)