ashb commented on a change in pull request #5339: [AIRFLOW-3160] (Unrevert) 
Load latest_dagruns asynchronously
URL: https://github.com/apache/airflow/pull/5339#discussion_r289061014
 
 

 ##########
 File path: airflow/www/views.py
 ##########
 @@ -403,6 +403,33 @@ def task_stats(self, session=None):
                 })
         return wwwutils.json_response(payload)
 
+    @expose('/last_dagruns')
+    @has_access
+    @provide_session
+    def last_dagruns(self, session=None):
+        DagRun = models.DagRun
+
+        filter_dag_ids = appbuilder.sm.get_accessible_dag_ids()
+
+        if not filter_dag_ids:
+            return
+
+        dags_to_latest_runs = dict(session.query(
+            DagRun.dag_id, 
sqla.func.max(DagRun.execution_date).label('execution_date'))
+            .group_by(DagRun.dag_id).all())
+
+        payload = {}
+        for dag in dagbag.dags.values():
+            dag_accessible = 'all_dags' in filter_dag_ids or dag.dag_id in 
filter_dag_ids
+            if (dag_accessible and dag.dag_id in dags_to_latest_runs and
+                    dags_to_latest_runs[dag.dag_id]):
+                payload[dag.safe_dag_id] = {
+                    'dag_id': dag.dag_id,
+                    'last_run': 
dags_to_latest_runs[dag.dag_id].strftime("%Y-%m-%d %H:%M")
 
 Review comment:
   This should probably be `.isoformat()`? (or at least include seconds and MS)

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to