Skip to content

Commit 2181bec

Browse files
committed
Refetch timings until script timings are present
1 parent 6067e10 commit 2181bec

File tree

2 files changed

+20
-7
lines changed

2 files changed

+20
-7
lines changed

site/src/api/queries/workspaceBuilds.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,14 +60,12 @@ export const infiniteWorkspaceBuilds = (
6060
// We use readyAgentsCount to invalidate the query when an agent connects
6161
export const workspaceBuildTimings = (
6262
workspaceBuildId: string,
63-
readyAgentsCount: number,
6463
) => {
6564
return {
6665
queryKey: [
6766
"workspaceBuilds",
6867
workspaceBuildId,
6968
"timings",
70-
{ readyAgentsCount },
7169
],
7270
queryFn: () => API.workspaceBuildTimings(workspaceBuildId),
7371
};

site/src/pages/WorkspacePage/WorkspaceReadyPage.tsx

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -157,13 +157,28 @@ export const WorkspaceReadyPage: FC<WorkspaceReadyPageProps> = ({
157157
// Cancel build
158158
const cancelBuildMutation = useMutation(cancelBuild(workspace, queryClient));
159159

160-
// Build Timings. Fetch build timings only when the build job is completed.
161-
const readyAgents = workspace.latest_build.resources
162-
.flatMap((r) => r.agents)
163-
.filter((a) => a && a.lifecycle_state !== "starting");
160+
// Workspace Timings.
164161
const timingsQuery = useQuery({
165-
...workspaceBuildTimings(workspace.latest_build.id, readyAgents.length),
162+
...workspaceBuildTimings(workspace.latest_build.id),
163+
164+
// Fetch build timings only when the build job is completed.
166165
enabled: Boolean(workspace.latest_build.job.completed_at),
166+
167+
// Sometimes, the timings can be fetched before the agent script timings are
168+
// done or saved in the database so we need to conditionally refetch the
169+
// timings. To refetch the timings, I found the best way was to compare the
170+
// expected amount of script timings with the current amount of script
171+
// timings returned in the response.
172+
refetchInterval: (data) => {
173+
const expectedScriptTimingsCount = workspace.latest_build.resources
174+
.flatMap((r) => r.agents)
175+
.flatMap((a) => a?.scripts)
176+
.filter((s) => s !== undefined).length;
177+
const currentScriptTimingsCount = data?.agent_script_timings?.length ?? 0;
178+
return expectedScriptTimingsCount === currentScriptTimingsCount
179+
? false
180+
: 1_000;
181+
},
167182
});
168183

169184
const runLastBuild = (

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy