From 618b673bc59084f8c921ba2440efa16b7ad6c213 Mon Sep 17 00:00:00 2001 From: Jakub Trllo <43494761+iLLiCiTiT@users.noreply.github.com> Date: Fri, 21 Aug 2026 13:54:09 +0200 Subject: [PATCH 1/5] add wait_for_events argument for operations endpoint --- ayon_api/_api_helpers/activities.py | 11 ++++++++--- ayon_api/_api_helpers/base.py | 1 + ayon_api/server_api.py | 25 ++++++++++++++++++------- 3 files changed, 27 insertions(+), 10 deletions(-) diff --git a/ayon_api/_api_helpers/activities.py b/ayon_api/_api_helpers/activities.py index 2428e3b54..b89729990 100644 --- a/ayon_api/_api_helpers/activities.py +++ b/ayon_api/_api_helpers/activities.py @@ -370,8 +370,10 @@ def send_activities_batch_operations( self, project_name: str, operations: list[dict[str, Any]], + *, can_fail: bool = False, - raise_on_fail: bool = True + wait_for_events: bool = False, + raise_on_fail: bool = True, ) -> list[dict[str, Any]]: """Post multiple CRUD activities operations to server. @@ -385,6 +387,8 @@ def send_activities_batch_operations( operations (list[dict[str, Any]]): Operations to be processed. can_fail (Optional[bool]): Server will try to process all operations even if one of them fails. + wait_for_events (bool): The operations are marked as done before + related events are triggered on server. raise_on_fail (Optional[bool]): Raise exception if an operation fails. You can handle failed operations on your own when set to 'False'. @@ -401,6 +405,7 @@ def send_activities_batch_operations( return self._send_batch_operations( f"projects/{project_name}/operations/activities", operations, - can_fail, - raise_on_fail, + can_fail=can_fail, + wait_for_events=wait_for_events, + raise_on_fail=raise_on_fail, ) diff --git a/ayon_api/_api_helpers/base.py b/ayon_api/_api_helpers/base.py index d9284207b..d852a95b4 100644 --- a/ayon_api/_api_helpers/base.py +++ b/ayon_api/_api_helpers/base.py @@ -167,6 +167,7 @@ def _send_batch_operations( uri: str, operations: list[dict[str, Any]], can_fail: bool, + wait_for_events: bool, raise_on_fail: bool ) -> list[dict[str, Any]]: raise NotImplementedError() diff --git a/ayon_api/server_api.py b/ayon_api/server_api.py index e27bcd496..46926d231 100644 --- a/ayon_api/server_api.py +++ b/ayon_api/server_api.py @@ -2475,7 +2475,9 @@ def send_batch_operations( self, project_name: str, operations: list[dict[str, Any]], + *, can_fail: bool = False, + wait_for_events: bool = False, raise_on_fail: bool = True, ) -> list[dict[str, Any]]: """Post multiple CRUD operations to server. @@ -2490,6 +2492,8 @@ def send_batch_operations( operations (list[dict[str, Any]]): Operations to be processed. can_fail (bool): Server will try to process all operations even if one of them fails. + wait_for_events (bool): The operations are marked as done before + related events are triggered on server. raise_on_fail (bool): Raise exception if an operation fails. You can handle failed operations on your own when set to 'False'. @@ -2506,8 +2510,9 @@ def send_batch_operations( return self._send_batch_operations( f"projects/{project_name}/operations", operations, - can_fail, - raise_on_fail, + can_fail=can_fail, + wait_for_events=wait_for_events, + raise_on_fail=raise_on_fail, ) def send_background_batch_operations( @@ -2516,8 +2521,9 @@ def send_background_batch_operations( operations: list[dict[str, Any]], *, can_fail: bool = False, - wait: bool = False, + wait_for_events: bool = False, raise_on_fail: bool = True, + wait: bool = False, ) -> BackgroundOperationTask: """Post multiple CRUD operations to server. @@ -2540,10 +2546,12 @@ def send_background_batch_operations( operations (list[dict[str, Any]]): Operations to be processed. can_fail (bool): Server will try to process all operations even if one of them fails. - wait (bool): Wait for operations to end. + wait_for_events (bool): The operations are marked as done before + related events are triggered on server. raise_on_fail (bool): Raise exception if an operation fails. You can handle failed operations on your own when set to 'False'. Used when 'wait' is enabled. + wait (bool): Wait for operations to end. Raises: ValueError: Operations can't be converted to json string. @@ -2558,7 +2566,8 @@ def send_background_batch_operations( response = self.post( f"projects/{project_name}/operations/background", operations=operations_body, - canFail=can_fail + canFail=can_fail, + waitForEvents=wait_for_events, ) response.raise_for_status() if not wait: @@ -2631,7 +2640,8 @@ def _send_batch_operations( uri: str, operations: list[dict[str, Any]], can_fail: bool, - raise_on_fail: bool + wait_for_events: bool, + raise_on_fail: bool, ) -> list[dict[str, Any]]: if not operations: return [] @@ -2643,7 +2653,8 @@ def _send_batch_operations( response = self.post( uri, operations=operations_body, - canFail=can_fail + canFail=can_fail, + waitForEvents=wait_for_events, ) op_results = response.get("operations") From 4d83829d6eac9aa87a9bb0cad0cc528d8d8c7c7c Mon Sep 17 00:00:00 2001 From: Jakub Trllo <43494761+iLLiCiTiT@users.noreply.github.com> Date: Fri, 21 Aug 2026 14:01:11 +0200 Subject: [PATCH 2/5] ad wait for events to the operations --- ayon_api/operations.py | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/ayon_api/operations.py b/ayon_api/operations.py index e39167a80..4dc034a0e 100644 --- a/ayon_api/operations.py +++ b/ayon_api/operations.py @@ -741,12 +741,21 @@ class OperationsSession(object): Args: con (Optional[ServerAPI]): Connection to server. Global connection is used if not passed. + wait_for_events (bool): Wait for events to be processed on server. + Default value of the argument. Can be changed when 'commit' + is called. """ - def __init__(self, con: Optional[ServerAPI] = None) -> None: + def __init__( + self, + con: Optional[ServerAPI] = None, + *, + wait_for_events: bool = False, + ) -> None: if con is None: con = get_server_api_connection() self._con = con + self._wait_for_events = wait_for_events self._project_cache = {} self._operations = [] self._nested_operations = collections.defaultdict(list) @@ -817,7 +826,7 @@ def to_data(self) -> list[dict[str, Any]]: for operation in self._operations ] - def commit(self) -> None: + def commit(self, *, wait_for_events: bool | None = None) -> None: """Commit session operations.""" operations, self._operations = self._operations, [] if not operations: @@ -827,6 +836,9 @@ def commit(self) -> None: for operation in operations: operations_by_project[operation.project_name].append(operation) + if wait_for_events is None: + wait_for_events = self._wait_for_events + for project_name, operations in operations_by_project.items(): operations_body = [] for operation in operations: @@ -835,7 +847,11 @@ def commit(self) -> None: operations_body.append(body) self._con.send_background_batch_operations( - project_name, operations_body, wait=True, can_fail=False + project_name, + operations_body, + can_fail=False, + wait_for_events=wait_for_events, + wait=True, ) def create_entity( From 49688f52adc137cd6b3c2fda35f76d696336c0e5 Mon Sep 17 00:00:00 2001 From: Jakub Trllo <43494761+iLLiCiTiT@users.noreply.github.com> Date: Fri, 21 Aug 2026 14:01:56 +0200 Subject: [PATCH 3/5] update public api --- ayon_api/_api.py | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/ayon_api/_api.py b/ayon_api/_api.py index dfa178e88..00f602fd7 100644 --- a/ayon_api/_api.py +++ b/ayon_api/_api.py @@ -1621,7 +1621,9 @@ def get_rest_entity_by_id( def send_batch_operations( project_name: str, operations: list[dict[str, Any]], + *, can_fail: bool = False, + wait_for_events: bool = False, raise_on_fail: bool = True, ) -> list[dict[str, Any]]: """Post multiple CRUD operations to server. @@ -1636,6 +1638,8 @@ def send_batch_operations( operations (list[dict[str, Any]]): Operations to be processed. can_fail (bool): Server will try to process all operations even if one of them fails. + wait_for_events (bool): The operations are marked as done before + related events are triggered on server. raise_on_fail (bool): Raise exception if an operation fails. You can handle failed operations on your own when set to 'False'. @@ -1654,6 +1658,7 @@ def send_batch_operations( project_name=project_name, operations=operations, can_fail=can_fail, + wait_for_events=wait_for_events, raise_on_fail=raise_on_fail, ) @@ -1663,8 +1668,9 @@ def send_background_batch_operations( operations: list[dict[str, Any]], *, can_fail: bool = False, - wait: bool = False, + wait_for_events: bool = False, raise_on_fail: bool = True, + wait: bool = False, ) -> BackgroundOperationTask: """Post multiple CRUD operations to server. @@ -1687,10 +1693,12 @@ def send_background_batch_operations( operations (list[dict[str, Any]]): Operations to be processed. can_fail (bool): Server will try to process all operations even if one of them fails. - wait (bool): Wait for operations to end. + wait_for_events (bool): The operations are marked as done before + related events are triggered on server. raise_on_fail (bool): Raise exception if an operation fails. You can handle failed operations on your own when set to 'False'. Used when 'wait' is enabled. + wait (bool): Wait for operations to end. Raises: ValueError: Operations can't be converted to json string. @@ -1706,8 +1714,9 @@ def send_background_batch_operations( project_name=project_name, operations=operations, can_fail=can_fail, - wait=wait, + wait_for_events=wait_for_events, raise_on_fail=raise_on_fail, + wait=wait, ) @@ -2709,7 +2718,9 @@ def set_entity_watchers( def send_activities_batch_operations( project_name: str, operations: list[dict[str, Any]], + *, can_fail: bool = False, + wait_for_events: bool = False, raise_on_fail: bool = True, ) -> list[dict[str, Any]]: """Post multiple CRUD activities operations to server. @@ -2724,6 +2735,8 @@ def send_activities_batch_operations( operations (list[dict[str, Any]]): Operations to be processed. can_fail (Optional[bool]): Server will try to process all operations even if one of them fails. + wait_for_events (bool): The operations are marked as done before + related events are triggered on server. raise_on_fail (Optional[bool]): Raise exception if an operation fails. You can handle failed operations on your own when set to 'False'. @@ -2742,6 +2755,7 @@ def send_activities_batch_operations( project_name=project_name, operations=operations, can_fail=can_fail, + wait_for_events=wait_for_events, raise_on_fail=raise_on_fail, ) From fbc7f5913dcf10a21669f39976fc428cd6f2b802 Mon Sep 17 00:00:00 2001 From: Jakub Trllo <43494761+iLLiCiTiT@users.noreply.github.com> Date: Fri, 21 Aug 2026 14:45:38 +0200 Subject: [PATCH 4/5] use better decription --- ayon_api/_api.py | 9 +++------ ayon_api/_api_helpers/activities.py | 3 +-- ayon_api/operations.py | 8 +++++++- ayon_api/server_api.py | 6 ++---- 4 files changed, 13 insertions(+), 13 deletions(-) diff --git a/ayon_api/_api.py b/ayon_api/_api.py index 00f602fd7..fd4bee8a3 100644 --- a/ayon_api/_api.py +++ b/ayon_api/_api.py @@ -1638,8 +1638,7 @@ def send_batch_operations( operations (list[dict[str, Any]]): Operations to be processed. can_fail (bool): Server will try to process all operations even if one of them fails. - wait_for_events (bool): The operations are marked as done before - related events are triggered on server. + wait_for_events (bool): Wait for events to be processed on server. raise_on_fail (bool): Raise exception if an operation fails. You can handle failed operations on your own when set to 'False'. @@ -1693,8 +1692,7 @@ def send_background_batch_operations( operations (list[dict[str, Any]]): Operations to be processed. can_fail (bool): Server will try to process all operations even if one of them fails. - wait_for_events (bool): The operations are marked as done before - related events are triggered on server. + wait_for_events (bool): Wait for events to be processed on server. raise_on_fail (bool): Raise exception if an operation fails. You can handle failed operations on your own when set to 'False'. Used when 'wait' is enabled. @@ -2735,8 +2733,7 @@ def send_activities_batch_operations( operations (list[dict[str, Any]]): Operations to be processed. can_fail (Optional[bool]): Server will try to process all operations even if one of them fails. - wait_for_events (bool): The operations are marked as done before - related events are triggered on server. + wait_for_events (bool): Wait for events to be processed on server. raise_on_fail (Optional[bool]): Raise exception if an operation fails. You can handle failed operations on your own when set to 'False'. diff --git a/ayon_api/_api_helpers/activities.py b/ayon_api/_api_helpers/activities.py index b89729990..277edaefa 100644 --- a/ayon_api/_api_helpers/activities.py +++ b/ayon_api/_api_helpers/activities.py @@ -387,8 +387,7 @@ def send_activities_batch_operations( operations (list[dict[str, Any]]): Operations to be processed. can_fail (Optional[bool]): Server will try to process all operations even if one of them fails. - wait_for_events (bool): The operations are marked as done before - related events are triggered on server. + wait_for_events (bool): Wait for events to be processed on server. raise_on_fail (Optional[bool]): Raise exception if an operation fails. You can handle failed operations on your own when set to 'False'. diff --git a/ayon_api/operations.py b/ayon_api/operations.py index 4dc034a0e..de9bf4549 100644 --- a/ayon_api/operations.py +++ b/ayon_api/operations.py @@ -827,7 +827,13 @@ def to_data(self) -> list[dict[str, Any]]: ] def commit(self, *, wait_for_events: bool | None = None) -> None: - """Commit session operations.""" + """Commit session operations. + + Args: + wait_for_events (bool | None): Wait for events to be processed + on server. Use 'None' to use the default value defined on + OperationsSession object. + """ operations, self._operations = self._operations, [] if not operations: return diff --git a/ayon_api/server_api.py b/ayon_api/server_api.py index 46926d231..9981554c9 100644 --- a/ayon_api/server_api.py +++ b/ayon_api/server_api.py @@ -2492,8 +2492,7 @@ def send_batch_operations( operations (list[dict[str, Any]]): Operations to be processed. can_fail (bool): Server will try to process all operations even if one of them fails. - wait_for_events (bool): The operations are marked as done before - related events are triggered on server. + wait_for_events (bool): Wait for events to be processed on server. raise_on_fail (bool): Raise exception if an operation fails. You can handle failed operations on your own when set to 'False'. @@ -2546,8 +2545,7 @@ def send_background_batch_operations( operations (list[dict[str, Any]]): Operations to be processed. can_fail (bool): Server will try to process all operations even if one of them fails. - wait_for_events (bool): The operations are marked as done before - related events are triggered on server. + wait_for_events (bool): Wait for events to be processed on server. raise_on_fail (bool): Raise exception if an operation fails. You can handle failed operations on your own when set to 'False'. Used when 'wait' is enabled. From e05fe55ccb255fbe05b20c5c387a5f39685d7819 Mon Sep 17 00:00:00 2001 From: Jakub Trllo <43494761+iLLiCiTiT@users.noreply.github.com> Date: Fri, 21 Aug 2026 14:46:58 +0200 Subject: [PATCH 5/5] add empty line --- ayon_api/operations.py | 1 + 1 file changed, 1 insertion(+) diff --git a/ayon_api/operations.py b/ayon_api/operations.py index de9bf4549..0ef2ce705 100644 --- a/ayon_api/operations.py +++ b/ayon_api/operations.py @@ -833,6 +833,7 @@ def commit(self, *, wait_for_events: bool | None = None) -> None: wait_for_events (bool | None): Wait for events to be processed on server. Use 'None' to use the default value defined on OperationsSession object. + """ operations, self._operations = self._operations, [] if not operations: