Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit2181bec

Browse files
committed
Refetch timings until script timings are present
1 parent6067e10 commit2181bec

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
exportconstworkspaceBuildTimings=(
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
constcancelBuildMutation=useMutation(cancelBuild(workspace,queryClient));
159159

160-
// Build Timings. Fetch build timings only when the build job is completed.
161-
constreadyAgents=workspace.latest_build.resources
162-
.flatMap((r)=>r.agents)
163-
.filter((a)=>a&&a.lifecycle_state!=="starting");
160+
// Workspace Timings.
164161
consttimingsQuery=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+
constexpectedScriptTimingsCount=workspace.latest_build.resources
174+
.flatMap((r)=>r.agents)
175+
.flatMap((a)=>a?.scripts)
176+
.filter((s)=>s!==undefined).length;
177+
constcurrentScriptTimingsCount=data?.agent_script_timings?.length??0;
178+
returnexpectedScriptTimingsCount===currentScriptTimingsCount
179+
?false
180+
:1_000;
181+
},
167182
});
168183

169184
construnLastBuild=(

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp