From 6fd1851ba9296d9736cb963101d821df5172d8d1 Mon Sep 17 00:00:00 2001 From: Leandro Poroli Date: Wed, 29 May 2024 09:58:50 -0300 Subject: [PATCH] adding retry strategy in KurtosisUpgrader --- .../enclaves/components/KurtosisUpgrader.tsx | 29 ++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/enclave-manager/web/packages/app/src/emui/enclaves/components/KurtosisUpgrader.tsx b/enclave-manager/web/packages/app/src/emui/enclaves/components/KurtosisUpgrader.tsx index 5d7682d6cf..110cf0b9bb 100644 --- a/enclave-manager/web/packages/app/src/emui/enclaves/components/KurtosisUpgrader.tsx +++ b/enclave-manager/web/packages/app/src/emui/enclaves/components/KurtosisUpgrader.tsx @@ -1,4 +1,5 @@ import { Alert, AlertDescription, AlertIcon, Box, Button, Flex } from "@chakra-ui/react"; +import { GetCloudInstanceConfigResponse } from "enclave-manager-sdk/build/kurtosis_backend_server_api_pb"; import { PropsWithChildren, useEffect, useState } from "react"; import { FiDownloadCloud, FiRotateCcw } from "react-icons/fi"; import { GoBug } from "react-icons/go"; @@ -58,6 +59,31 @@ export const KurtosisUpgrader = () => { } }; + const wait = (ms: number) => { + return new Promise((resolve) => setTimeout(resolve, ms)); + }; + + const getCloudInstanceConfigWithRetry = async ( + tries: number, + interval: number, + ): Promise => { + let getCloudInstanceConfigResponse: GetCloudInstanceConfigResponse = new GetCloudInstanceConfigResponse(); + try { + getCloudInstanceConfigResponse = await kurtosisClient.getCloudInstanceConfig(skipCache); + } catch (e) { + const newTries = tries - 1; + + if (newTries === 0) { + throw e; + } + + await wait(interval); + + return getCloudInstanceConfigWithRetry(newTries, interval); + } + return getCloudInstanceConfigResponse; + }; + // Check once on load if a new Kurtosis version is available useEffect(() => { if (!kurtosisClient.isRunningInCloud()) return; @@ -74,7 +100,8 @@ export const KurtosisUpgrader = () => { const interval = setInterval(async () => { try { - const getCloudInstanceConfigResponse = await kurtosisClient.getCloudInstanceConfig(skipCache); + // Calling it with retries because when the engine is restarted it won't return a response for a few seconds + const getCloudInstanceConfigResponse = await getCloudInstanceConfigWithRetry(5, 2000); const instanceStatus = getCloudInstanceConfigResponse.status; if (instanceStatus === "running") { setUpgradeStatus(UpgradeStatus.SUCCESS);