-
Notifications
You must be signed in to change notification settings - Fork 876
fix: display build timings when all timings are loaded #15728
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
Merged
Merged
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
6067e10
Improve comments
BrunoQuaresma 2181bec
Refetch timings until script timings are present
BrunoQuaresma b16fad1
Stay on loading state when agent script timings are empty
BrunoQuaresma 53f267b
Fix fmt
BrunoQuaresma 0c7abee
Apply review suggestions
BrunoQuaresma File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Refetch timings until script timings are present
- Loading branch information
commit 2181bec72b5334e5e15dc575d2234860be02920b
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -157,13 +157,28 @@ export const WorkspaceReadyPage: FC<WorkspaceReadyPageProps> = ({ | |
// Cancel build | ||
const cancelBuildMutation = useMutation(cancelBuild(workspace, queryClient)); | ||
|
||
// Build Timings. Fetch build timings only when the build job is completed. | ||
const readyAgents = workspace.latest_build.resources | ||
.flatMap((r) => r.agents) | ||
.filter((a) => a && a.lifecycle_state !== "starting"); | ||
// Workspace Timings. | ||
const timingsQuery = useQuery({ | ||
...workspaceBuildTimings(workspace.latest_build.id, readyAgents.length), | ||
...workspaceBuildTimings(workspace.latest_build.id), | ||
|
||
// Fetch build timings only when the build job is completed. | ||
enabled: Boolean(workspace.latest_build.job.completed_at), | ||
|
||
// Sometimes, the timings can be fetched before the agent script timings are | ||
// done or saved in the database so we need to conditionally refetch the | ||
// timings. To refetch the timings, I found the best way was to compare the | ||
// expected amount of script timings with the current amount of script | ||
// timings returned in the response. | ||
refetchInterval: (data) => { | ||
const expectedScriptTimingsCount = workspace.latest_build.resources | ||
.flatMap((r) => r.agents) | ||
.flatMap((a) => a?.scripts) | ||
.filter((s) => s !== undefined).length; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Tiny nit, but I want to say this can be cleaned up as: const expectedScriptTimingsCount = workspace.latest_build.resources
.flatMap((r) => r.agents)
.flatMap((a) => a?.scripts ?? []).length; |
||
const currentScriptTimingsCount = data?.agent_script_timings?.length ?? 0; | ||
return expectedScriptTimingsCount === currentScriptTimingsCount | ||
? false | ||
: 1_000; | ||
}, | ||
}); | ||
|
||
const runLastBuild = ( | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
What was the
readyAgentCount
value doing before? I see that we were only using it for the query key, and now it's goneThere 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.
It was to refetch the query when a new agent was marked as ready but it was very buggy and a bad decision on my end. The current refetch logic makes more sense and it is easier to follow.