From b2a473f337826ec1161a6aa224d3dcf1e1b0f0fe Mon Sep 17 00:00:00 2001 From: Alexander Petric Date: Wed, 29 Oct 2025 17:00:58 -0400 Subject: [PATCH] feat: add cancel_job to windmill python client (#6995) --- python-client/wmill/wmill/client.py | 35 +++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/python-client/wmill/wmill/client.py b/python-client/wmill/wmill/client.py index 36e7f7dc9a..d01eb55762 100644 --- a/python-client/wmill/wmill/client.py +++ b/python-client/wmill/wmill/client.py @@ -337,6 +337,27 @@ class Windmill: time.sleep(0.5) + def cancel_job(self, job_id: str, reason: str = None) -> str: + """Cancel a specific job by ID. + + Args: + job_id: UUID of the job to cancel + reason: Optional reason for cancellation + + Returns: + Response message from the cancel endpoint + """ + logger.info(f"cancelling job: {job_id}") + + payload = {"reason": reason or "cancelled via cancel_job method"} + + response = self.post( + f"/w/{self.workspace}/jobs_u/queue/cancel/{job_id}", + json=payload, + ) + + return response.text + def cancel_running(self) -> dict: """Cancel currently running executions of the same script.""" logger.info("canceling running executions of this script") @@ -1363,6 +1384,20 @@ def send_teams_message( return _client.send_teams_message(conversation_id, text, success, card_block) +@init_global_client +def cancel_job(job_id: str, reason: str = None) -> str: + """Cancel a specific job by ID. + + Args: + job_id: UUID of the job to cancel + reason: Optional reason for cancellation + + Returns: + Response message from the cancel endpoint + """ + return _client.cancel_job(job_id, reason) + + @init_global_client def cancel_running() -> dict: """Cancel currently running executions of the same script."""