From 469c7500e8ff62d67f3a9acd97061fe982673140 Mon Sep 17 00:00:00 2001 From: Dan Homola Date: Wed, 28 May 2025 11:09:13 +0200 Subject: [PATCH] feat: add cancel method to the Execution object This makes the DX of cancelling a single execution nicer. It does not throw an exception in case the ExecutionDefinition under the hood is not cancellable, it would only add friction. JIRA: CQ-1124 risk: low --- .../gooddata_sdk/compute/model/execution.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/gooddata-sdk/gooddata_sdk/compute/model/execution.py b/gooddata-sdk/gooddata_sdk/compute/model/execution.py index 55615f69c..daf6e2dad 100644 --- a/gooddata-sdk/gooddata_sdk/compute/model/execution.py +++ b/gooddata-sdk/gooddata_sdk/compute/model/execution.py @@ -8,6 +8,7 @@ from attrs import define, field from gooddata_api_client import models from gooddata_api_client.model.afm import AFM +from gooddata_api_client.model.afm_cancel_tokens import AfmCancelTokens from gooddata_api_client.model.result_spec import ResultSpec from gooddata_sdk.client import GoodDataApiClient @@ -360,6 +361,16 @@ def read_result(self, limit: Union[int, list[int]], offset: Union[None, int, lis ) return ExecutionResult(execution_result) + def cancel(self) -> None: + """ + Cancels the execution backing this execution result. + """ + if self.cancel_token is not None: + self._api_client.actions_api.cancel_executions( + self._workspace_id, + AfmCancelTokens({self.result_id: self.cancel_token}), + ) + def __str__(self) -> str: return self.__repr__() @@ -437,6 +448,12 @@ def get_labels_and_formats(self) -> tuple[dict[str, str], dict[str, str]]: def read_result(self, limit: Union[int, list[int]], offset: Union[None, int, list[int]] = None) -> ExecutionResult: return self.bare_exec_response.read_result(limit, offset) + def cancel(self) -> None: + """ + Cancels the execution. + """ + self.bare_exec_response.cancel() + def __str__(self) -> str: return self.__repr__()