From 80a38d824f5c7fee69c687f5c295be5d4316550a Mon Sep 17 00:00:00 2001 From: Adam Fiedler Date: Tue, 15 Apr 2025 17:44:40 +0200 Subject: [PATCH] feat: add a global executions_cancellable option jira: cq-1123 risk: low --- gooddata-sdk/gooddata_sdk/client.py | 11 +++++++++++ gooddata-sdk/gooddata_sdk/compute/service.py | 4 +++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/gooddata-sdk/gooddata_sdk/client.py b/gooddata-sdk/gooddata_sdk/client.py index 708f5e300..6e411d847 100644 --- a/gooddata-sdk/gooddata_sdk/client.py +++ b/gooddata-sdk/gooddata_sdk/client.py @@ -24,6 +24,7 @@ def __init__( token: str, custom_headers: Optional[dict[str, str]] = None, extra_user_agent: Optional[str] = None, + executions_cancellable: bool = False, ) -> None: """Take url, token for connecting to GoodData.CN. @@ -32,6 +33,11 @@ def __init__( `extra_user_agent` is optional string to be added to default http User-Agent header. This takes precedence over custom_headers setting. + + `executions_cancellable` is a flag that sets all executions computed through this client as cancellable. + In case a request for a result is interrupted, the GD server will try to free resources like killing sql queries + related to the given execution. + *This feature does not work yet, it will be rolled out soon.* """ self._hostname = host self._token = token @@ -57,6 +63,7 @@ def __init__( self._layout_api = apis.LayoutApi(self._api_client) self._actions_api = apis.ActionsApi(self._api_client) self._user_management_api = apis.UserManagementApi(self._api_client) + self._executions_cancellable = executions_cancellable def _do_post_request( self, @@ -138,3 +145,7 @@ def actions_api(self) -> apis.ActionsApi: @property def user_management_api(self) -> apis.UserManagementApi: return self._user_management_api + + @property + def executions_cancellable(self) -> bool: + return self._executions_cancellable diff --git a/gooddata-sdk/gooddata_sdk/compute/service.py b/gooddata-sdk/gooddata_sdk/compute/service.py index bbf810aee..1e25a598a 100644 --- a/gooddata-sdk/gooddata_sdk/compute/service.py +++ b/gooddata-sdk/gooddata_sdk/compute/service.py @@ -42,7 +42,9 @@ def for_exec_def(self, workspace_id: str, exec_def: ExecutionDefinition) -> Exec workspace_id=workspace_id, exec_def=exec_def, response=response, - cancel_token=response.headers.get("X-GDC-CANCEL-TOKEN") if exec_def.is_cancellable else None, + cancel_token=response.headers.get("X-GDC-CANCEL-TOKEN") + if exec_def.is_cancellable or self._api_client.executions_cancellable + else None, ) def retrieve_result_cache_metadata(self, workspace_id: str, result_id: str) -> ResultCacheMetadata: