-
Notifications
You must be signed in to change notification settings - Fork 14.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Only refresh active dags on dags page #24770
Only refresh active dags on dags page #24770
Conversation
airflow/www/static/js/dags.js
Outdated
@@ -485,6 +515,8 @@ $(window).on('load', () => { | |||
$('body').on('mouseout', '.has-svg-tooltip', () => { | |||
hideSvgTooltip(); | |||
}); | |||
|
|||
refreshDagStats(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
refreshDagStats
uses jQuery, so I brought it inside the page load callback with the other init functions.
airflow/www/static/js/dags.js
Outdated
@@ -428,17 +433,42 @@ function refreshDagRuns(error, json) { | |||
}); | |||
} | |||
|
|||
function handleRefresh() { | |||
function getAllDagIds() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
getAllDagIds
and getActiveDagIds
return an array of dag ids. Passing either function to handleRefresh
or refreshDagStats
let's the developer specify all / just a subset of dag ids to use in the HTTP request.
airflow/www/static/js/dags.js
Outdated
$('.js-loading-dag-stats').remove(); | ||
function refreshDagStats(getDagIds) { | ||
if (typeof getDagIds !== 'function') { | ||
getDagIds = getAllDagIds; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added a getDagIds
argument here to keep the behavior consistent with the handleRefresh
function. It's unused, so I can remove it if requested.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As in my comment below, let's remove it if we're not using it. No need for excess code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not a big fan of passing functions and then reassigning those arguments in refreshDagStats()
and handleRefresh()
. It's a lot of extra logic to follow. I think it would be clearer to pass a refreshAll boolean variable, and even combine getDagIds and getAllDagIds into a single function.
Therefore it would look more like:
function handleRefresh(refreshAllDags = false) {
const dagIds = getDagIds(refreshAllDags);
dagIds.forEach((dagId) => {
params.append('dag_ids', dagId);
});
airflow/www/static/js/dags.js
Outdated
// no dags, hide the loading dots | ||
$('.js-loading-task-stats').remove(); | ||
$('.js-loading-dag-stats').remove(); | ||
function refreshDagStats(getDagIds) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should this be called getDagStats
since we only call it once? We don't ever call it with getDagIds
either
@bbovenzi Thanks for the review! I made changes based on your feedback.
Thanks for your insight. While I think passing functions can make the code more extensible/tolerant to change (kind of like the strategy pattern in OOP) it definitely isn't required to complete this task. I do think passing functions has benefits (like the following), so I hope we can consider this approach in the future, maybe in a different context. benefits in this case:
Thanks again. |
My main issue was reassigning the parameter. |
@bbovenzi I went ahead and changed the function signatures. |
Looking better! Although, it looks like we have 2 errors from |
Co-authored-by: Brent Bovenzi <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice work!
closes: #23949
related: #22900
Summary
This PR changes the behavior of the auto-refresh feature on the dags page. Auto-refresh currently targeted all dags. This PR modifies the behavior to only targets active (ie. unpaused) dags.
A few important notes:
This behavior makes the most sense to me, but I have no problem changing it if requested.
Demo
issue-23949.mp4