Skip to content
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

Merged
merged 7 commits into from
Jul 13, 2022

Conversation

hankehly
Copy link
Contributor

@hankehly hankehly commented Jul 1, 2022

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:

  • Clicking the refresh button (the circular arrow icon) at the top right of the page still refreshes all dags.
  • If there are no active dags, and the "auto-refresh" switch is enabled, no request is sent and the switch stays enabled.

This behavior makes the most sense to me, but I have no problem changing it if requested.

Demo

issue-23949.mp4

@boring-cyborg boring-cyborg bot added area:UI Related to UI/UX. For Frontend Developers. area:webserver Webserver related Issues labels Jul 1, 2022
@@ -485,6 +515,8 @@ $(window).on('load', () => {
$('body').on('mouseout', '.has-svg-tooltip', () => {
hideSvgTooltip();
});

refreshDagStats();
Copy link
Contributor Author

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.

@@ -428,17 +433,42 @@ function refreshDagRuns(error, json) {
});
}

function handleRefresh() {
function getAllDagIds() {
Copy link
Contributor Author

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.

$('.js-loading-dag-stats').remove();
function refreshDagStats(getDagIds) {
if (typeof getDagIds !== 'function') {
getDagIds = getAllDagIds;
Copy link
Contributor Author

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.

Copy link
Contributor

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.

@hankehly hankehly marked this pull request as ready for review July 1, 2022 01:45
Copy link
Contributor

@bbovenzi bbovenzi left a 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);
  });

// no dags, hide the loading dots
$('.js-loading-task-stats').remove();
$('.js-loading-dag-stats').remove();
function refreshDagStats(getDagIds) {
Copy link
Contributor

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

@hankehly
Copy link
Contributor Author

hankehly commented Jul 9, 2022

@bbovenzi Thanks for the review!

I made changes based on your feedback.

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.

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:

  • by passing in a different function to handleRefresh, we can modify its behavior without changing its implementation/tests
  • writing out something like handleRefresh(getAllDagIds) gives a little more information about which dags are being targeted as opposed to handleRefresh(true) (if only we could write handleRefresh(activeOnly=true))

Thanks again.

@hankehly hankehly requested a review from bbovenzi July 9, 2022 04:13
@bbovenzi
Copy link
Contributor

bbovenzi commented Jul 9, 2022

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:

  • by passing in a different function to handleRefresh, we can modify its behavior without changing its implementation/tests
  • writing out something like handleRefresh(getAllDagIds) gives a little more information about which dags are being targeted as opposed to handleRefresh(true) (if only we could write handleRefresh(activeOnly=true))

My main issue was reassigning the parameter.
I agree that just true isn't too descriptive. We can turn the props into an object handleRefresh({ activeOnly = true }).

@hankehly
Copy link
Contributor Author

@bbovenzi I went ahead and changed the function signatures. handleRefresh({ activeDagsOnly: true }) is definitely more clear.

@bbovenzi
Copy link
Contributor

Looking better! Although, it looks like we have 2 errors from yarn lint. Fix those and I think this should be good to go

@hankehly hankehly requested a review from bbovenzi July 12, 2022 23:30
Copy link
Contributor

@bbovenzi bbovenzi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice work!

@bbovenzi bbovenzi merged commit 2a1472a into apache:main Jul 13, 2022
@bbovenzi bbovenzi added this to the Airflow 2.4.0 milestone Jul 13, 2022
@hankehly hankehly deleted the issue-23949-only-refresh-active-dags branch July 14, 2022 00:35
@ephraimbuddy ephraimbuddy added the type:improvement Changelog: Improvements label Aug 12, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:UI Related to UI/UX. For Frontend Developers. area:webserver Webserver related Issues type:improvement Changelog: Improvements
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Only autorefresh active dags on home page
3 participants