Skip to content

Commit 520bbd0

Browse files
committed
feat: add support for cancel api
jira: cq-1123 risk: low
1 parent ce27f75 commit 520bbd0

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

gooddata-sdk/gooddata_sdk/compute/service.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
import logging
55

6+
from gooddata_api_client.model.afm_cancel_tokens import AfmCancelTokens
67
from gooddata_api_client.model.chat_history_request import ChatHistoryRequest
78
from gooddata_api_client.model.chat_history_result import ChatHistoryResult
89
from gooddata_api_client.model.chat_request import ChatRequest
@@ -108,3 +109,22 @@ def ai_chat_history_reset(self, workspace_id: str) -> None:
108109
"""
109110
chat_history_request = ChatHistoryRequest(reset=True)
110111
self._actions_api.ai_chat_history(workspace_id, chat_history_request, _check_return_type=False)
112+
113+
def cancel_executions(self, executions: list[Execution]) -> None:
114+
"""
115+
Try to cancel given executions using the cancel api endpoint.
116+
117+
Args:
118+
executions: list of executions to cancel
119+
"""
120+
workspace_to_tokens: dict[str, set[str]] = {}
121+
122+
for execution in executions:
123+
if not workspace_to_tokens[execution.workspace_id]:
124+
workspace_to_tokens[execution.workspace_id] = set()
125+
126+
if execution.cancel_token:
127+
workspace_to_tokens[execution.workspace_id].add(execution.cancel_token)
128+
129+
for workspace_id, token_ids in workspace_to_tokens.items():
130+
self._actions_api.cancel_executions(workspace_id, AfmCancelTokens(list(token_ids)))

0 commit comments

Comments
 (0)