From 4b6c7b860dcd9304b0090678949769b7aa7aec96 Mon Sep 17 00:00:00 2001 From: Sujit Date: Mon, 30 Sep 2024 13:17:52 +0545 Subject: [PATCH 1/2] feat(task-description): retry image processing trigger api failure if the status code is 304 and the failure is less than 5 times --- .../DescriptionSection/PopoverBox/ImageBox/index.tsx | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/frontend/src/components/DroneOperatorTask/DescriptionSection/PopoverBox/ImageBox/index.tsx b/src/frontend/src/components/DroneOperatorTask/DescriptionSection/PopoverBox/ImageBox/index.tsx index c455a560..9a97bfd3 100644 --- a/src/frontend/src/components/DroneOperatorTask/DescriptionSection/PopoverBox/ImageBox/index.tsx +++ b/src/frontend/src/components/DroneOperatorTask/DescriptionSection/PopoverBox/ImageBox/index.tsx @@ -54,6 +54,8 @@ const ImageBoxPopOver = () => { const { mutate: startImageryProcess } = useMutation({ mutationFn: () => postProcessImagery(projectId, taskId), onSuccess: () => toast.success('Image processing started'), + retry: (failureCount: any, error: any) => + error.status === 304 && failureCount < 5, }); // function that gets the signed urls for the images and again puts them in chunks of 4 From ab22820633f1026c86702bde77b7e0fc30f18589 Mon Sep 17 00:00:00 2001 From: Sujit Date: Mon, 30 Sep 2024 13:28:09 +0545 Subject: [PATCH 2/2] feat(task-description-image-upload): implement `retryFc` to retry the api in case of upload failure after 1 sec --- .../src/utils/callApiSimultaneously.ts | 29 ++++++++++++++++--- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/src/frontend/src/utils/callApiSimultaneously.ts b/src/frontend/src/utils/callApiSimultaneously.ts index e6a58fbb..e82582bd 100644 --- a/src/frontend/src/utils/callApiSimultaneously.ts +++ b/src/frontend/src/utils/callApiSimultaneously.ts @@ -1,10 +1,31 @@ import axios from 'axios'; +import { toast } from 'react-toastify'; // function that calls the api simultaneously export default async function callApiSimultaneously(urls: any, data: any) { - const promises = urls.map((url: any, index: any) => - axios.put(url, data[index]), + // eslint-disable-next-line no-promise-executor-return + const delay = (ms: number) => new Promise(resolve => setTimeout(resolve, ms)); + + const retryFc = async (url: string, singleData: any, n: number) => { + try { + return await axios.put(url, singleData); + } catch (err) { + if (n === 1) throw err; + delay(1000); // 1 sec delay + // eslint-disable-next-line no-return-await + return await retryFc(url, singleData, n - 1); + } + }; + + const promises = urls.map( + (url: any, index: any) => retryFc(url, data[index], 3), // 3 entries for each api call ); - const responses = await Promise.all(promises); - return responses; + + try { + const responses = await Promise.all(promises); + return responses; + } catch (err) { + toast.error('Error occurred on image upload'); + throw err; + } }