Skip to content

Commit

Permalink
wait 1 second and retry when 429 on upload (#1316)
Browse files Browse the repository at this point in the history
  • Loading branch information
ebrehault authored Feb 12, 2024
1 parent d6774db commit 2b8dc8d
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
2 changes: 1 addition & 1 deletion apps/desktop/electron/src/service/sync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ function syncFiles() {
}

const batch: Observable<{ id: string; success: boolean }>[] = source.items
.slice(0, 10)
.slice(0, 5)
.map((item) =>
of(item).pipe(
switchMap((item) =>
Expand Down
10 changes: 8 additions & 2 deletions libs/sdk-core/src/lib/db/upload.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {
catchError,
concatMap,
delay,
filter,
from,
map,
Expand All @@ -10,6 +11,7 @@ import {
of,
range,
repeat,
retry,
startWith,
switchMap,
take,
Expand Down Expand Up @@ -98,9 +100,10 @@ export const uploadFile = (
'content-type': metadata?.contentType || 'application/octet-stream',
...getFileMetadata(metadata),
};
let retries = 1;
let retries = 3;
const slug = metadata?.rslug ? `?rslug=${metadata.rslug}` : '';
return nuclia.rest.post<Response>(`${path}/upload${slug}`, buffer, headers, true).pipe(
switchMap((res) => (res.status === 429 ? of(res).pipe(delay(1000)) : of(res))),
repeat(),
filter((res) => retries-- === 0 || res.status !== 503),
take(1),
Expand Down Expand Up @@ -161,8 +164,9 @@ export const TUSuploadFile = (
if (uploadMetadata.length > 0) {
headers['upload-metadata'] = uploadMetadata.join(',');
}
let retries = 1;
let retries = 3;
return nuclia.rest.post<Response>(`${path}/tusupload`, creationPayload, headers, true).pipe(
switchMap((res) => (res.status === 429 ? of(res).pipe(delay(1000)) : of(res))),
repeat(),
filter((res) => retries-- === 0 || res.status !== 503),
catchError((error) => of(error)),
Expand Down Expand Up @@ -195,6 +199,8 @@ export const TUSuploadFile = (
true,
)
.pipe(
switchMap((res) => (res.status === 429 ? of(res).pipe(delay(1000)) : of(res))),
retry(3),
map((res) => {
if (res.status !== 200) {
failed = true;
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "nuclia",
"version": "2.7.7",
"version": "2.7.8",
"license": "MIT",
"author": "Nuclia.cloud",
"description": "Nuclia frontend apps and libs",
Expand Down

0 comments on commit 2b8dc8d

Please sign in to comment.