Skip to content

Commit

Permalink
Improve graph view refresh (#16696)
Browse files Browse the repository at this point in the history
* Improve graph view refresh

- only refresh if state has actually changed

- stop refresh if all states are final

- swap out `.attr()` to `.prop()` for handling `checked` see https://stackoverflow.com/questions/5874652/prop-vs-attr

* check only on final states instead of pending
  • Loading branch information
bbovenzi authored Jul 8, 2021
1 parent 5999cb9 commit c3dd89c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
21 changes: 18 additions & 3 deletions airflow/www/static/js/graph.js
Original file line number Diff line number Diff line change
Expand Up @@ -364,14 +364,29 @@ function setFocusMap(state) {

const stateIsSet = () => !!Object.keys(stateFocusMap).find((key) => stateFocusMap[key]);

let prevTis;

function handleRefresh() {
$('#loading-dots').css('display', 'inline-block');
$.get(getTaskInstanceURL)
.done(
(tis) => {
// only refresh if the data has changed
if (prevTis !== tis) {
// eslint-disable-next-line no-global-assign
taskInstances = JSON.parse(tis);
updateNodesStates(taskInstances);
taskInstances = JSON.parse(tis);
const states = Object.values(taskInstances).map((ti) => ti.state);
updateNodesStates(taskInstances);

// end refresh if all states are final
if (!states.some((state) => (
['success', 'failed', 'upstream_failed', 'skipped', 'removed'].indexOf(state) === -1))
) {
$('#auto_refresh').prop('checked', false);
clearInterval(refreshInterval);
}
}
prevTis = tis;
setTimeout(() => { $('#loading-dots').hide(); }, 500);
$('#error').hide();
},
Expand Down Expand Up @@ -409,7 +424,7 @@ $('#auto_refresh').change(() => {

function initRefresh() {
if (localStorage.getItem('disableAutoRefresh')) {
$('#auto_refresh').removeAttr('checked');
$('#auto_refresh').prop('checked', false);
}
startOrStopRefresh();
d3.select('#refresh_button').on('click', () => handleRefresh());
Expand Down
4 changes: 2 additions & 2 deletions airflow/www/static/js/tree.js
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,7 @@ document.addEventListener('DOMContentLoaded', () => {
if (getActiveRuns()) {
handleRefresh();
} else {
$('#auto_refresh').removeAttr('checked');
$('#auto_refresh').prop('checked', false);
}
}, 3000); // run refresh every 3 seconds
} else {
Expand All @@ -480,7 +480,7 @@ document.addEventListener('DOMContentLoaded', () => {
function initRefresh() {
// default to auto-refresh if there are any active dag runs
if (getActiveRuns() && !localStorage.getItem('disableAutoRefresh')) {
$('#auto_refresh').attr('checked', true);
$('#auto_refresh').prop('checked', true);
}
startOrStopRefresh();
d3.select('#refresh_button').on('click', () => handleRefresh());
Expand Down

0 comments on commit c3dd89c

Please sign in to comment.