mirror of
https://github.com/fosrl/pangolin.git
synced 2025-07-13 23:45:00 +02:00
Speed up when the button shows
This commit is contained in:
parent
f438d2ddbf
commit
17919192e0
3 changed files with 10 additions and 19 deletions
|
@ -154,6 +154,11 @@ async function triggerFetch(siteId: number) {
|
||||||
`Triggering fetch containers for site ${siteId} with Newt ${newt.newtId}`
|
`Triggering fetch containers for site ${siteId} with Newt ${newt.newtId}`
|
||||||
);
|
);
|
||||||
fetchContainers(newt.newtId);
|
fetchContainers(newt.newtId);
|
||||||
|
|
||||||
|
// clear the cache for this Newt ID so that the site has to keep asking for the containers
|
||||||
|
// this is to ensure that the site always gets the latest data
|
||||||
|
dockerSocketCache.del(`${newt.newtId}:dockerContainers`);
|
||||||
|
|
||||||
return { siteId, newtId: newt.newtId };
|
return { siteId, newtId: newt.newtId };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -78,12 +78,6 @@ export const ContainersSelector: FC<ContainerSelectorProps> = ({
|
||||||
}
|
}
|
||||||
}, [isAvailable]);
|
}, [isAvailable]);
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
if (isAvailable && containers.length === 0) {
|
|
||||||
fetchContainers();
|
|
||||||
}
|
|
||||||
}, [isAvailable, containers.length]);
|
|
||||||
|
|
||||||
if (!site || !isAvailable) {
|
if (!site || !isAvailable) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
|
@ -121,16 +121,12 @@ export function useDockerSocket(siteId: number) {
|
||||||
if (error?.response?.status === 425) {
|
if (error?.response?.status === 425) {
|
||||||
if (attempt < maxRetries) {
|
if (attempt < maxRetries) {
|
||||||
// Ask the newt server to check containers
|
// Ask the newt server to check containers
|
||||||
await getContainers();
|
await fetchContainerList();
|
||||||
// Exponential backoff: 2s, 4s, 8s...
|
|
||||||
const retryDelay = Math.min(
|
|
||||||
2000 * Math.pow(2, attempt - 1),
|
|
||||||
10000
|
|
||||||
);
|
|
||||||
console.log(
|
console.log(
|
||||||
`Containers not ready yet (attempt ${attempt}/${maxRetries}). Retrying in ${retryDelay}ms...`
|
`Containers not ready yet (attempt ${attempt}/${maxRetries}). Retrying in 250ms...`
|
||||||
);
|
);
|
||||||
await sleep(retryDelay);
|
await sleep(250);
|
||||||
continue;
|
continue;
|
||||||
} else {
|
} else {
|
||||||
console.warn(
|
console.warn(
|
||||||
|
@ -166,7 +162,6 @@ export function useDockerSocket(siteId: number) {
|
||||||
const res = await api.post<AxiosResponse<TriggerFetchResponse>>(
|
const res = await api.post<AxiosResponse<TriggerFetchResponse>>(
|
||||||
`/site/${siteId}/docker/trigger`
|
`/site/${siteId}/docker/trigger`
|
||||||
);
|
);
|
||||||
await sleep(1000); // Wait a second before fetching containers
|
|
||||||
// TODO: identify a way to poll the server for latest container list periodically?
|
// TODO: identify a way to poll the server for latest container list periodically?
|
||||||
await fetchContainerList();
|
await fetchContainerList();
|
||||||
return res.data.data;
|
return res.data.data;
|
||||||
|
@ -188,11 +183,8 @@ export function useDockerSocket(siteId: number) {
|
||||||
}
|
}
|
||||||
|
|
||||||
checkDockerSocket();
|
checkDockerSocket();
|
||||||
const timeout = setTimeout(() => {
|
getDockerSocketStatus();
|
||||||
getDockerSocketStatus();
|
|
||||||
}, 3000);
|
|
||||||
|
|
||||||
return () => clearTimeout(timeout);
|
|
||||||
}, [isEnabled, isAvailable, checkDockerSocket, getDockerSocketStatus]);
|
}, [isEnabled, isAvailable, checkDockerSocket, getDockerSocketStatus]);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue