dstandish commented on code in PR #53429:
URL: https://github.com/apache/airflow/pull/53429#discussion_r2219697898
##########
airflow-core/src/airflow/api_fastapi/core_api/routes/ui/dags.py:
##########
@@ -191,3 +195,36 @@ def get_dags(
total_entries=total_entries,
dags=list(dag_runs_by_dag_id.values()),
)
+
+
+@dags_router.get(
+ "/{dag_id}/latest_run",
+ responses=create_openapi_http_exception_doc([status.HTTP_404_NOT_FOUND]),
+ dependencies=[Depends(requires_access_dag(method="GET",
access_entity=DagAccessEntity.RUN))],
+)
+def get_latest_run_info(dag_id: str, session: SessionDep) ->
list[DAGRunLightResponse]:
+ """Get latest run."""
+ if dag_id == "~":
+ raise HTTPException(
+ status.HTTP_400_BAD_REQUEST,
+ "`~` was supplied as dag_id, but querying multiple dags is not
supported.",
Review Comment:
I also don't buy the maintenance argument. Like, look ta this endpoint.
```
def get_latest_run(
dag_id: str,
session: SessionDep,
) -> LatestRunResponse | None:
"""
Get information about the latest dag run by run_after.
This is used by the UI to figure out if it needs to rerun queries and
resume auto refresh.
"""
return session.execute(
select(
DagRun.id,
DagRun.dag_id,
DagRun.run_id,
DagRun.run_after,
)
.where(DagRun.dag_id == dag_id)
.order_by(DagRun.run_after.desc())
.limit(1)
).one_or_none()
```
There is no maintenance burden here. It's extremely simple. It's basically
a one liner that does what it needs to do and nothing more.
I don't think that you get to better maintainability by making the public
endpoint super polymorphic, with conditionals for how to query etc, and the
coupling that doing so entails.
--
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]