henry3260 commented on code in PR #72917:
URL: https://github.com/apache/airflow/pull/72917#discussion_r4431994252
##########
task-sdk/src/airflow/sdk/api/client.py:
##########
@@ -1015,10 +1015,35 @@ def trigger(
return OKResponse(ok=True)
- def clear(self, dag_id: str, run_id: str) -> OKResponse:
+ def clear(self, dag_id: str, run_id: str) -> OKResponse | ErrorResponse:
"""Clear a Dag run via the API server."""
- self.client.post(f"dag-runs/{dag_id}/{run_id}/clear")
- # TODO: Error handling
+ try:
+ self.client.post(f"dag-runs/{dag_id}/{run_id}/clear")
+ except ServerResponseError as e:
+ detail = {
+ "dag_id": dag_id,
+ "run_id": run_id,
+ "status_code": e.response.status_code,
+ "server_detail": e.detail,
+ }
+ if e.response.status_code == HTTPStatus.NOT_FOUND:
+ error = ErrorType.DAGRUN_CLEAR_FAILED
+ if isinstance(e.detail, dict):
+ message = str(e.detail.get("message", ""))
+ if message.startswith("Dag run "):
Review Comment:
I think we can merge these into just `DAGRUN_CLEAR_FAILED`. The other two
aren't
consumed anywhere yet, and matching on the server's message string isn't
reliable.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]