Skip to content

Commit

Permalink
Merge pull request #78 from hatchet-dev/belanger/add-cancel-api-2
Browse files Browse the repository at this point in the history
feat: cancel via rest api
  • Loading branch information
grutt authored Jul 8, 2024
2 parents 17ffdbd + de82f72 commit 21b9914
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
12 changes: 12 additions & 0 deletions hatchet_sdk/clients/rest_client.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
from typing import Any, Dict

from hatchet_sdk.clients.rest.models.workflow_runs_cancel_request import (
WorkflowRunsCancelRequest,
)

from .rest.api.log_api import LogApi
from .rest.api.step_run_api import StepRunApi
from .rest.api.workflow_api import WorkflowApi
Expand Down Expand Up @@ -62,6 +66,14 @@ def workflow_run_get(self, workflow_run_id: str):
workflow_run=workflow_run_id,
)

def workflow_run_cancel(self, workflow_run_id: str):
return self.workflow_run_api.workflow_run_cancel(
tenant=self.tenant_id,
workflow_runs_cancel_request=WorkflowRunsCancelRequest(
workflowRunIds=[workflow_run_id],
),
)

def workflow_run_create(self, workflow_id: str, input: Dict[str, Any]):
return self.workflow_run_api.workflow_run_create(
workflow=workflow_id,
Expand Down
3 changes: 1 addition & 2 deletions hatchet_sdk/worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -432,8 +432,7 @@ async def handle_cancel_action(self, run_id: str):
# check if thread is still running, if so, print a warning
if run_id in self.threads:
logger.warning(
f"""Thread {self.threads[run_id].ident} with run id {run_id} is still running after cancellation.
This could cause the thread pool to get blocked and prevent new tasks from running."""
f"Thread {self.threads[run_id].ident} with run id {run_id} is still running after cancellation. This could cause the thread pool to get blocked and prevent new tasks from running."
)
finally:
self.cleanup_run_id(run_id)
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "hatchet-sdk"
version = "0.27.6"
version = "0.28.0"
description = ""
authors = ["Alexander Belanger <[email protected]>"]
readme = "README.md"
Expand Down

0 comments on commit 21b9914

Please sign in to comment.