Skip to content

Commit ee2aeb4

Browse files
fix: avoid pulling containers when it is not enabled (#17855)
We've been continuously pulling the containers endpoint even when the agent does not support containers. To optimize the requests, we can check if it is throwing an error and stop if it is a 403 status code.
1 parent c42a315 commit ee2aeb4

File tree

2 files changed

+12
-16
lines changed

2 files changed

+12
-16
lines changed

site/src/api/api.ts

+5-15
Original file line numberDiff line numberDiff line change
@@ -2453,21 +2453,11 @@ class ApiMethods {
24532453
const params = new URLSearchParams(
24542454
labels?.map((label) => ["label", label]),
24552455
);
2456-
2457-
try {
2458-
const res =
2459-
await this.axios.get<TypesGen.WorkspaceAgentListContainersResponse>(
2460-
`/api/v2/workspaceagents/${agentId}/containers?${params.toString()}`,
2461-
);
2462-
return res.data;
2463-
} catch (err) {
2464-
// If the error is a 403, it means that experimental
2465-
// containers are not enabled on the agent.
2466-
if (isAxiosError(err) && err.response?.status === 403) {
2467-
return { containers: [] };
2468-
}
2469-
throw err;
2470-
}
2456+
const res =
2457+
await this.axios.get<TypesGen.WorkspaceAgentListContainersResponse>(
2458+
`/api/v2/workspaceagents/${agentId}/containers?${params.toString()}`,
2459+
);
2460+
return res.data;
24712461
};
24722462

24732463
getInboxNotifications = async (startingBeforeId?: string) => {

site/src/modules/resources/AgentRow.tsx

+7-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import type {
1010
WorkspaceAgent,
1111
WorkspaceAgentMetadata,
1212
} from "api/typesGenerated";
13+
import { isAxiosError } from "axios";
1314
import { DropdownArrow } from "components/DropdownArrow/DropdownArrow";
1415
import type { Line } from "components/Logs/LogLine";
1516
import { Stack } from "components/Stack/Stack";
@@ -160,7 +161,12 @@ export const AgentRow: FC<AgentRowProps> = ({
160161
select: (res) => res.containers.filter((c) => c.status === "running"),
161162
// TODO: Implement a websocket connection to get updates on containers
162163
// without having to poll.
163-
refetchInterval: 10_000,
164+
refetchInterval: (_, query) => {
165+
const { error } = query.state;
166+
return isAxiosError(error) && error.response?.status === 403
167+
? false
168+
: 10_000;
169+
},
164170
});
165171

166172
return (

0 commit comments

Comments
 (0)