Skip to content

Commit 3ea3d54

Browse files
committed
fix: expose pickup form of StartTransaction (#838)
1 parent 91362d5 commit 3ea3d54

7 files changed

Lines changed: 417 additions & 3 deletions

File tree

packages/uipath-platform/pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "uipath-platform"
3-
version = "0.1.46"
3+
version = "0.1.47"
44
description = "HTTP client library for programmatic access to UiPath Platform"
55
readme = { file = "README.md", content-type = "text/markdown" }
66
requires-python = ">=3.11"

packages/uipath-platform/src/uipath/platform/orchestrator/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
CommitType,
2828
QueueItem,
2929
QueueItemPriority,
30+
Strategy,
3031
TransactionItem,
3132
TransactionItemResult,
3233
)
@@ -56,6 +57,7 @@
5657
"CommitType",
5758
"QueueItem",
5859
"QueueItemPriority",
60+
"Strategy",
5961
"TransactionItem",
6062
"TransactionItemResult",
6163
"McpServer",

packages/uipath-platform/src/uipath/platform/orchestrator/_queues_service.py

Lines changed: 168 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from datetime import datetime
12
from typing import Any, Dict, List, Optional, Union
23

34
from httpx import Response
@@ -12,6 +13,7 @@
1213
from .queues import (
1314
CommitType,
1415
QueueItem,
16+
Strategy,
1517
TransactionItem,
1618
TransactionItemResult,
1719
)
@@ -286,6 +288,120 @@ async def create_transaction_item_async(
286288
)
287289
return response.json()
288290

291+
@resource_override(resource_type="queue", resource_identifier="queue_name")
292+
@traced(name="queues_start_transaction_item", run_type="uipath")
293+
def start_transaction_item(
294+
self,
295+
queue_name: str,
296+
*,
297+
reference: str | None = None,
298+
reference_filter_option: Strategy | None = None,
299+
defer_date: datetime | None = None,
300+
due_date: datetime | None = None,
301+
parent_operation_id: str | None = None,
302+
no_robot: bool = False,
303+
folder_key: str | None = None,
304+
folder_path: str | None = None,
305+
) -> Response:
306+
"""Picks up the next available item from a queue and transitions it to ``In Progress``.
307+
308+
Use this when you want to process an item that already exists in the queue (e.g. one
309+
added previously via `create_item`). Orchestrator returns the item now in
310+
``In Progress`` status, whose ``Key`` can then be passed to
311+
`update_progress_of_transaction_item` and `complete_transaction_item`.
312+
313+
Args:
314+
queue_name: Name of the queue to pick the next item from.
315+
reference (str | None): If provided, restricts the pickup to items whose
316+
``Reference`` matches this value (filter strategy controlled by
317+
``reference_filter_option``).
318+
reference_filter_option (Strategy | None): Strategy used to match
319+
``reference``. Defaults to ``Strategy.EQUALS`` semantics on the server when
320+
``reference`` is set.
321+
defer_date (datetime | None): Earliest date/time at which the item is
322+
available for processing.
323+
due_date (datetime | None): Latest date/time by which the item should be
324+
processed.
325+
parent_operation_id (str | None): Operation id of the caller, propagated to
326+
the picked-up item.
327+
no_robot: If True, the transaction will not be associated with a robot.
328+
Defaults to False.
329+
folder_key (str | None): The key of the folder. Overrides the default one set in the SDK config.
330+
folder_path (str | None): The path of the folder. Overrides the default one set in the SDK config.
331+
332+
Returns:
333+
Response: HTTP response containing the queue item now in ``In Progress`` state.
334+
"""
335+
spec = self._start_transaction_item_spec(
336+
queue_name=queue_name,
337+
reference=reference,
338+
reference_filter_option=reference_filter_option,
339+
defer_date=defer_date,
340+
due_date=due_date,
341+
parent_operation_id=parent_operation_id,
342+
no_robot=no_robot,
343+
folder_key=folder_key,
344+
folder_path=folder_path,
345+
)
346+
response = self.request(
347+
spec.method, url=spec.endpoint, json=spec.json, headers=spec.headers
348+
)
349+
return response.json()
350+
351+
@resource_override(resource_type="queue", resource_identifier="queue_name")
352+
@traced(name="queues_start_transaction_item", run_type="uipath")
353+
async def start_transaction_item_async(
354+
self,
355+
queue_name: str,
356+
*,
357+
reference: str | None = None,
358+
reference_filter_option: Strategy | None = None,
359+
defer_date: datetime | None = None,
360+
due_date: datetime | None = None,
361+
parent_operation_id: str | None = None,
362+
no_robot: bool = False,
363+
folder_key: str | None = None,
364+
folder_path: str | None = None,
365+
) -> Response:
366+
"""Asynchronously picks up the next available item from a queue and transitions it to ``In Progress``.
367+
368+
See `start_transaction_item` for behavior details.
369+
370+
Args:
371+
queue_name: Name of the queue to pick the next item from.
372+
reference (str | None): If provided, restricts the pickup to items whose
373+
``Reference`` matches this value.
374+
reference_filter_option (Strategy | None): Strategy used to match ``reference``.
375+
defer_date (datetime | None): Earliest date/time at which the item is
376+
available for processing.
377+
due_date (datetime | None): Latest date/time by which the item should be
378+
processed.
379+
parent_operation_id (str | None): Operation id of the caller, propagated to
380+
the picked-up item.
381+
no_robot: If True, the transaction will not be associated with a robot.
382+
Defaults to False.
383+
folder_key (str | None): The key of the folder. Overrides the default one set in the SDK config.
384+
folder_path (str | None): The path of the folder. Overrides the default one set in the SDK config.
385+
386+
Returns:
387+
Response: HTTP response containing the queue item now in ``In Progress`` state.
388+
"""
389+
spec = self._start_transaction_item_spec(
390+
queue_name=queue_name,
391+
reference=reference,
392+
reference_filter_option=reference_filter_option,
393+
defer_date=defer_date,
394+
due_date=due_date,
395+
parent_operation_id=parent_operation_id,
396+
no_robot=no_robot,
397+
folder_key=folder_key,
398+
folder_path=folder_path,
399+
)
400+
response = await self.request_async(
401+
spec.method, url=spec.endpoint, json=spec.json, headers=spec.headers
402+
)
403+
return response.json()
404+
289405
@resource_override(resource_type="queue", resource_identifier="queue_name")
290406
@traced(name="queues_update_progress_of_transaction_item", run_type="uipath")
291407
def update_progress_of_transaction_item(
@@ -299,6 +415,10 @@ def update_progress_of_transaction_item(
299415
) -> Response:
300416
"""Updates the progress of a transaction item.
301417
418+
The item must already be in ``In Progress`` state. Use `create_transaction_item`
419+
to create-and-start a new item, or `start_transaction_item` to pick up an
420+
existing one.
421+
302422
Args:
303423
transaction_key: Unique identifier of the transaction.
304424
progress: Progress message to set.
@@ -332,6 +452,10 @@ async def update_progress_of_transaction_item_async(
332452
) -> Response:
333453
"""Asynchronously updates the progress of a transaction item.
334454
455+
The item must already be in ``In Progress`` state. Use `create_transaction_item`
456+
to create-and-start a new item, or `start_transaction_item` to pick up an
457+
existing one.
458+
335459
Args:
336460
transaction_key: Unique identifier of the transaction.
337461
progress: Progress message to set.
@@ -365,6 +489,9 @@ def complete_transaction_item(
365489
) -> Response:
366490
"""Completes a transaction item with the specified result.
367491
492+
The item must already be in ``In Progress`` state, having been created via
493+
`create_transaction_item` or picked up via `start_transaction_item`.
494+
368495
Args:
369496
transaction_key: Unique identifier of the transaction to complete.
370497
result: Result data for the transaction, either as a dictionary or TransactionItemResult instance.
@@ -398,6 +525,9 @@ async def complete_transaction_item_async(
398525
) -> Response:
399526
"""Asynchronously completes a transaction item with the specified result.
400527
528+
The item must already be in ``In Progress`` state, having been created via
529+
`create_transaction_item` or picked up via `start_transaction_item`.
530+
401531
Args:
402532
transaction_key: Unique identifier of the transaction to complete.
403533
result: Result data for the transaction, either as a dictionary or TransactionItemResult instance.
@@ -545,6 +675,44 @@ def _create_transaction_item_spec(
545675
},
546676
)
547677

678+
def _start_transaction_item_spec(
679+
self,
680+
*,
681+
queue_name: str,
682+
reference: str | None = None,
683+
reference_filter_option: Strategy | None = None,
684+
defer_date: datetime | None = None,
685+
due_date: datetime | None = None,
686+
parent_operation_id: str | None = None,
687+
no_robot: bool = False,
688+
folder_key: str | None = None,
689+
folder_path: str | None = None,
690+
) -> RequestSpec:
691+
transaction_data: Dict[str, Any] = {"Name": queue_name}
692+
if not no_robot:
693+
transaction_data["RobotIdentifier"] = self._execution_context.robot_key
694+
if reference is not None:
695+
transaction_data["Reference"] = reference
696+
if reference_filter_option is not None:
697+
transaction_data["ReferenceFilterOption"] = reference_filter_option.value
698+
if defer_date is not None:
699+
transaction_data["DeferDate"] = defer_date.isoformat()
700+
if due_date is not None:
701+
transaction_data["DueDate"] = due_date.isoformat()
702+
if parent_operation_id is not None:
703+
transaction_data["ParentOperationId"] = parent_operation_id
704+
705+
return RequestSpec(
706+
method="POST",
707+
endpoint=Endpoint(
708+
"/orchestrator_/odata/Queues/UiPathODataSvc.StartTransaction"
709+
),
710+
json={"transactionData": transaction_data},
711+
headers={
712+
**header_folder(folder_key, folder_path),
713+
},
714+
)
715+
548716
def _update_progress_of_transaction_item_spec(
549717
self,
550718
transaction_key: str,

packages/uipath-platform/src/uipath/platform/orchestrator/queues.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,13 @@ class CommitType(Enum):
2525
PROCESS_ALL_INDEPENDENTLY = "ProcessAllIndependently"
2626

2727

28+
class Strategy(Enum):
29+
"""Strategy used to filter the Reference value on StartTransaction."""
30+
31+
EQUALS = "Equals"
32+
STARTS_WITH = "StartsWith"
33+
34+
2835
class QueueItem(BaseModel):
2936
"""Model representing an item in an Orchestrator queue."""
3037

@@ -173,6 +180,18 @@ def warn_name_deprecated(cls, values: Any) -> Any:
173180
description="Operation id which created the queue item.",
174181
alias="ParentOperationId",
175182
)
183+
reference: (
184+
Annotated[str, Field(min_length=0, strict=True, max_length=128)] | None
185+
) = Field(
186+
default=None,
187+
description="An optional, user-specified value for queue item identification.",
188+
alias="Reference",
189+
)
190+
reference_filter_option: Strategy | None = Field(
191+
default=None,
192+
description="Declares the strategy used to filter the Reference value.",
193+
alias="ReferenceFilterOption",
194+
)
176195

177196

178197
class TransactionItemResult(BaseModel):

0 commit comments

Comments
 (0)