fixed retry method

This commit is contained in:
Abhinav-grd 2021-07-26 20:54:14 +05:30
parent 8761696f28
commit af27e583da
3 changed files with 10 additions and 10 deletions

View file

@ -1,4 +1,4 @@
import { retryPromise, runningInBrowser } from 'utils/common';
import { retryAsyncFunction, runningInBrowser } from 'utils/common';
import { getExportPendingFiles, getExportFailedFiles, getFilesUploadedAfterLastExport, getFileUID, dedupe, getGoogleLikeMetadataFile } from 'utils/export';
import { logError } from 'utils/sentry';
import { getData, LS_KEYS } from 'utils/storage/localStorage';
@ -254,7 +254,7 @@ class ExportService {
const uid = `${file.id}_${this.sanitizeName(
file.metadata.title,
)}`;
const fileStream = await retryPromise(downloadManager.downloadFile(file));
const fileStream = await retryAsyncFunction(()=>downloadManager.downloadFile(file));
this.ElectronAPIs.saveStreamToDisk(`${collectionPath}/${uid}`, fileStream);
this.ElectronAPIs.saveFileToDisk(
`${collectionPath}/${MetadataFolderName}/${uid}.json`,

View file

@ -4,7 +4,7 @@ import EXIF from 'exif-js';
import { File, fileAttribute } from './fileService';
import { Collection } from './collectionService';
import { FILE_TYPE, SetFiles } from 'pages/gallery';
import { checkConnectivity, retryPromise, sleep } from 'utils/common';
import { checkConnectivity, retryAsyncFunction, sleep } from 'utils/common';
import {
handleError,
parseError,
@ -570,7 +570,7 @@ class UploadService {
if (!token) {
return;
}
const response = await retryPromise(HTTPService.post(
const response = await retryAsyncFunction(()=>HTTPService.post(
`${ENDPOINT}/files`,
uploadFile,
null,
@ -896,7 +896,7 @@ class UploadService {
filename: string,
): Promise<string> {
try {
await retryPromise(
await retryAsyncFunction(()=>
HTTPService.put(
fileUploadURL.url,
file,
@ -940,7 +940,7 @@ class UploadService {
}
}
const uploadChunk = Uint8Array.from(combinedChunks);
const response = await retryPromise(
const response = await retryAsyncFunction(()=>
HTTPService.put(
fileUploadURL,
uploadChunk,
@ -959,7 +959,7 @@ class UploadService {
{ CompleteMultipartUpload: { Part: resParts } },
options,
);
await retryPromise(
await retryAsyncFunction(()=>
HTTPService.post(multipartUploadURLs.completeURL, body, null, {
'content-type': 'text/xml',
}),

View file

@ -32,14 +32,14 @@ export function reverseString(title: string) {
.reduce((reversedString, currWord) => `${currWord} ${reversedString}`);
}
export async function retryPromise(promise: Promise<any>, retryCount: number = 3) {
export async function retryAsyncFunction(func: ()=>Promise<any>, retryCount: number = 3) {
try {
const resp = await promise;
const resp = await func();
return resp;
} catch (e) {
if (retryCount > 0) {
await sleep(retrySleepTime[3 - retryCount]);
await retryPromise(promise, retryCount - 1);
await retryAsyncFunction(func, retryCount - 1);
} else {
throw e;
}