Skip to content

Commit

Permalink
Fix graph autorefresh on page load (#21736)
Browse files Browse the repository at this point in the history
* fix auto refresh check on page load

* minor code cleanup

* remove new line

(cherry picked from commit b2c0a92)
  • Loading branch information
bbovenzi authored and ephraimbuddy committed Mar 22, 2022
1 parent 713b5c2 commit 116916d
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions airflow/www/static/js/graph.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,13 @@ const stateFocusMap = {
deferred: false,
no_status: false,
};

const checkRunState = () => {
const states = Object.values(taskInstances).map((ti) => ti.state);
return !states.some((state) => (
['success', 'failed', 'upstream_failed', 'skipped', 'removed'].indexOf(state) === -1));
};

const taskTip = d3.tip()
.attr('class', 'tooltip d3-tip')
.html((toolTipHtml) => toolTipHtml);
Expand Down Expand Up @@ -362,13 +369,11 @@ function handleRefresh() {
if (prevTis !== tis) {
// eslint-disable-next-line no-global-assign
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))
) {
const isFinal = checkRunState();
if (isFinal) {
$('#auto_refresh').prop('checked', false);
clearInterval(refreshInterval);
}
Expand Down Expand Up @@ -410,9 +415,9 @@ $('#auto_refresh').change(() => {
});

function initRefresh() {
if (localStorage.getItem('disableAutoRefresh')) {
$('#auto_refresh').prop('checked', false);
}
const isDisabled = localStorage.getItem('disableAutoRefresh');
const isFinal = checkRunState();
$('#auto_refresh').prop('checked', !(isDisabled || isFinal));
startOrStopRefresh();
d3.select('#refresh_button').on('click', () => handleRefresh());
}
Expand Down

0 comments on commit 116916d

Please sign in to comment.