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

Fix Stdout and File Section not working/refreshing #4029

Merged
merged 12 commits into from
Mar 2, 2022
Merged

Fix Stdout and File Section not working/refreshing #4029

merged 12 commits into from
Mar 2, 2022

Conversation

jzwang43
Copy link
Contributor

@jzwang43 jzwang43 commented Feb 22, 2022

Reasons for making this change

Previously the front end was constantly sending request to the back end even if the previous one was pending, added state variables to keep track of pending request so we don't overwhelm the back end.

Related issues

fixes #3994

Screenshots

a

No extra request when the call is pending.

Also tested while sleep 2; do echo thinking; done, and it's updating file.

Checklist

  • I've added a screenshot of the changes, if this is a frontend change
  • I've added and/or updated tests, if this is a backend change
  • I've run the pre-commit.sh script
  • I've updated docs, if needed

@jzwang43 jzwang43 changed the title Stdout and File Section not working/refreshing Fix Stdout and File Section not working/refreshing Feb 22, 2022
@jzwang43 jzwang43 marked this pull request as ready for review February 22, 2022 22:36
@jzwang43 jzwang43 marked this pull request as draft February 22, 2022 22:58
@jzwang43 jzwang43 marked this pull request as ready for review February 22, 2022 23:08
Copy link
Member

@epicfaace epicfaace left a comment

Choose a reason for hiding this comment

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

Added a suggestion to use .finally instead. This is because we have to call setFetchingMetadata / setPendingFileSummaryFetches when each network promise either succeeds or fails, and .finally avoids duplication. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/finally

Can you also test this locally to ensure it does refresh? I don't think the PR as it is now would have worked -- because setFetchingMetadata(false) is currently not called on success of fetcherMetadata.

return fetchFileSummary(uuid, '/').then(function(blob) {
setPendingFileSummaryFetches((f) => f - 1);
setFileContents(blob);
setStderr(null);
setStdout(null);
Copy link
Member

Choose a reason for hiding this comment

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

we should replace this with .finally(() => setPendingFileSummaryFetches((f) => f - 1)) (so this will be called whether the promise succeeds or fails)

);
} else {
stateUpdate[name] = null;
}
});
Promise.all(fetchRequests).then((r) => {
setPendingFileSummaryFetches((f) => f - 1);
setFileContents(stateUpdate['fileContents']);
Copy link
Member

Choose a reason for hiding this comment

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

we should replace this with .finally(() => setPendingFileSummaryFetches((f) => f - 1)) (so this will be called whether the promise succeeds or fails)

.then(function(blob) {
stateUpdate[name] = blob;
})
.catch((e) => {
Copy link
Member

Choose a reason for hiding this comment

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

we should replace this with .finally(() => setPendingFileSummaryFetches((f) => f - 1)) (so this will be called whether the promise succeeds or fails)

@jzwang43
Copy link
Contributor Author

jzwang43 commented Mar 1, 2022

Added a suggestion to use .finally instead. This is because we have to call setFetchingMetadata / setPendingFileSummaryFetches when each network promise either succeeds or fails, and .finally avoids duplication. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/finally

Can you also test this locally to ensure it does refresh? I don't think the PR as it is now would have worked -- because setFetchingMetadata(false) is currently not called on success of fetcherMetadata.

setFetchingMetadata(false) is called in onSuccess in useSWR, it should be moved to finally as well. But yeah I tested before and it's working.

Thanks for the suggestion of using finally, I'll update that.

@epicfaace
Copy link
Member

setFetchingMetadata(false) is called in onSuccess in useSWR,

ooh interesting, where in the code? Can't seem to locate it

@@ -152,6 +166,7 @@ const BundleDetail = ({
revalidateOnMount: true,
refreshInterval: refreshInterval,
onSuccess: (response) => {
setFetchingMetadata(false);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@epicfaace it's here:)

Copy link
Member

Choose a reason for hiding this comment

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

Wait, why do we call setFetchingMetadata after call fetcherContents? Shouldn't we call setFetchingMetadata only after calling fetcherMetadata?

Copy link
Contributor Author

@jzwang43 jzwang43 Mar 1, 2022

Choose a reason for hiding this comment

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

Yeah just cleaned up everything with finally

Copy link
Member

@epicfaace epicfaace left a comment

Choose a reason for hiding this comment

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

One more thing -- I think we should also add the finally... code to fetcherContents? Because the same issue could happen with that network request as well?

Feel free to merge after adding that.

@mergify mergify bot merged commit 3f839db into master Mar 2, 2022
@mergify mergify bot deleted the fix/3994 branch March 2, 2022 22:21
@epicfaace
Copy link
Member

epicfaace commented Mar 3, 2022 via email

@teetone teetone mentioned this pull request Mar 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Stdout and File Section not working/refreshing
2 participants