uranusjr commented on a change in pull request #18675:
URL: https://github.com/apache/airflow/pull/18675#discussion_r727529032
##########
File path: airflow/www/views.py
##########
@@ -219,6 +219,82 @@ def get_date_time_num_runs_dag_runs_form_data(www_request,
session, dag):
}
+def task_group_to_tree(task_group, dag, dag_runs, tis):
+ """
+ Create a nested dict representation of this TaskGroup and its children
used to construct
+ the Graph.
+ """
+ if isinstance(task_group, BaseOperator):
Review comment:
`task_item_or_group`? (And we can assign it to new names after the
`isinstance()` check)
##########
File path: airflow/www/static/js/tree/useTreeData.js
##########
@@ -0,0 +1,79 @@
+/*!
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+/* global treeData, localStorage, fetch, autoRefreshInterval */
+
+import { useState, useEffect, useCallback } from 'react';
+import { useDisclosure } from '@chakra-ui/react';
+import camelcaseKeys from 'camelcase-keys';
+
+import getMetaValue from '../meta_value';
+
+// dagId comes from dag.html
+const dagId = getMetaValue('dag_id');
+const treeDataUrl = getMetaValue('tree_data');
+const numRuns = getMetaValue('num_runs');
+const urlRoot = getMetaValue('root');
+const isPaused = getMetaValue('is_paused');
+
+const areActiveRuns = (runs) => runs.filter((run) => ['queued', 'running',
'scheduled'].includes(run.state)).length > 0;
+
+const useTreeData = () => {
+ const [data, setData] = useState(camelcaseKeys(JSON.parse(treeData), { deep:
true }));
+ const defaultIsOpen = isPaused !== 'True' &&
(JSON.parse(localStorage.getItem('disableAutoRefresh')) ||
areActiveRuns(data.dagRuns));
+ const { isOpen, onToggle } = useDisclosure({ defaultIsOpen });
+
+ const handleRefresh = useCallback(async () => {
+ const resp = await
fetch(`${treeDataUrl}?dag_id=${dagId}&num_runs=${numRuns}&root=${urlRoot}`);
+ let newData = await resp.json();
+ newData = camelcaseKeys(newData, { deep: true });
+ if (JSON.stringify(newData) !== JSON.stringify(data)) {
Review comment:
Python dicts are insertion-ordered (from 3.6 up at least), so this
should be mostly stable. The most likely source of issues would be the first
refresh, because the initial `treeData` is from the HTML, but subsequent runs
use the JSON-based view, and those are more likely to have inconsistencies if
we're not careful. I kind of wonder if we should get rid of the initial
`treeData` and always render from the JSON view.
The other significant possibility of inconsistencies is SQL natural
ordering, but those can be caught incrementally if needed.
--
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]