diff --git a/server/routers/site/socketIntegration.ts b/server/routers/site/socketIntegration.ts index cc2aac6c..2b9ed39a 100644 --- a/server/routers/site/socketIntegration.ts +++ b/server/routers/site/socketIntegration.ts @@ -154,6 +154,11 @@ async function triggerFetch(siteId: number) { `Triggering fetch containers for site ${siteId} with Newt ${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 }; } diff --git a/src/components/ContainersSelector.tsx b/src/components/ContainersSelector.tsx index 6cd9f4d5..6c7c1368 100644 --- a/src/components/ContainersSelector.tsx +++ b/src/components/ContainersSelector.tsx @@ -78,12 +78,6 @@ export const ContainersSelector: FC = ({ } }, [isAvailable]); - useEffect(() => { - if (isAvailable && containers.length === 0) { - fetchContainers(); - } - }, [isAvailable, containers.length]); - if (!site || !isAvailable) { return null; } diff --git a/src/hooks/useDockerSocket.ts b/src/hooks/useDockerSocket.ts index 4ec9bdf2..ef188ac4 100644 --- a/src/hooks/useDockerSocket.ts +++ b/src/hooks/useDockerSocket.ts @@ -121,16 +121,12 @@ export function useDockerSocket(siteId: number) { if (error?.response?.status === 425) { if (attempt < maxRetries) { // Ask the newt server to check containers - await getContainers(); - // Exponential backoff: 2s, 4s, 8s... - const retryDelay = Math.min( - 2000 * Math.pow(2, attempt - 1), - 10000 - ); + await fetchContainerList(); + 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; } else { console.warn( @@ -166,7 +162,6 @@ export function useDockerSocket(siteId: number) { const res = await api.post>( `/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? await fetchContainerList(); return res.data.data; @@ -188,11 +183,8 @@ export function useDockerSocket(siteId: number) { } checkDockerSocket(); - const timeout = setTimeout(() => { - getDockerSocketStatus(); - }, 3000); + getDockerSocketStatus(); - return () => clearTimeout(timeout); }, [isEnabled, isAvailable, checkDockerSocket, getDockerSocketStatus]); return {