Skip to content

Commit 469c750

Browse files
committed
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
1 parent 3d4cd5a commit 469c750

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

gooddata-sdk/gooddata_sdk/compute/model/execution.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from attrs import define, field
99
from gooddata_api_client import models
1010
from gooddata_api_client.model.afm import AFM
11+
from gooddata_api_client.model.afm_cancel_tokens import AfmCancelTokens
1112
from gooddata_api_client.model.result_spec import ResultSpec
1213

1314
from gooddata_sdk.client import GoodDataApiClient
@@ -360,6 +361,16 @@ def read_result(self, limit: Union[int, list[int]], offset: Union[None, int, lis
360361
)
361362
return ExecutionResult(execution_result)
362363

364+
def cancel(self) -> None:
365+
"""
366+
Cancels the execution backing this execution result.
367+
"""
368+
if self.cancel_token is not None:
369+
self._api_client.actions_api.cancel_executions(
370+
self._workspace_id,
371+
AfmCancelTokens({self.result_id: self.cancel_token}),
372+
)
373+
363374
def __str__(self) -> str:
364375
return self.__repr__()
365376

@@ -437,6 +448,12 @@ def get_labels_and_formats(self) -> tuple[dict[str, str], dict[str, str]]:
437448
def read_result(self, limit: Union[int, list[int]], offset: Union[None, int, list[int]] = None) -> ExecutionResult:
438449
return self.bare_exec_response.read_result(limit, offset)
439450

451+
def cancel(self) -> None:
452+
"""
453+
Cancels the execution.
454+
"""
455+
self.bare_exec_response.cancel()
456+
440457
def __str__(self) -> str:
441458
return self.__repr__()
442459

0 commit comments

Comments
 (0)