Skip to content

Commit

Permalink
Merge pull request #246 from hotosm/feat/user-profile
Browse files Browse the repository at this point in the history
Feat: Retry on api failure on image upload and image processing trigger.
  • Loading branch information
nrjadkry authored Sep 30, 2024
2 parents 1be28d0 + 0d4222b commit 7c542e9
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
29 changes: 25 additions & 4 deletions src/frontend/src/utils/callApiSimultaneously.ts
Original file line number Diff line number Diff line change
@@ -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;
}
}

0 comments on commit 7c542e9

Please sign in to comment.