fix(fe/chunk_uploader): improve robustness of chunk uploader
This commit is contained in:
parent
aa56b935a2
commit
33ca87cf2c
2 changed files with 11 additions and 18 deletions
|
@ -16,7 +16,7 @@ const chunkLimit = 1024 * 1024 * 50; // 50MB
|
||||||
const createRetryLimit = 1024;
|
const createRetryLimit = 1024;
|
||||||
const uploadRetryLimit = 1024;
|
const uploadRetryLimit = 1024;
|
||||||
const readRetryLimit = 8;
|
const readRetryLimit = 8;
|
||||||
const backoffMax = 2000;
|
const backoffMax = 5000;
|
||||||
|
|
||||||
export interface ReaderResult {
|
export interface ReaderResult {
|
||||||
chunk?: string;
|
chunk?: string;
|
||||||
|
@ -56,9 +56,9 @@ export class ChunkUploader {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
await this.backOff();
|
|
||||||
console.error(e);
|
console.error(e);
|
||||||
}
|
}
|
||||||
|
await this.backOff();
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
@ -130,21 +130,11 @@ export class ChunkUploader {
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
let uploadResp: Response<UploadStatusResp> = undefined;
|
const uploadResp = await this.client.uploadChunk(
|
||||||
for (let i = 0; i < uploadRetryLimit; i++) {
|
filePath,
|
||||||
uploadResp = await this.client.uploadChunk(
|
result.chunk,
|
||||||
filePath,
|
uploaded
|
||||||
result.chunk,
|
);
|
||||||
uploaded
|
|
||||||
);
|
|
||||||
|
|
||||||
if (uploadResp.status === 200) {
|
|
||||||
break;
|
|
||||||
} else if (uploadResp.status !== 429) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
await this.backOff();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (uploadResp.status === 200 && uploadResp.data != null) {
|
if (uploadResp.status === 200 && uploadResp.data != null) {
|
||||||
this.chunkLen = Math.ceil(this.chunkLen * speedUpRatio);
|
this.chunkLen = Math.ceil(this.chunkLen * speedUpRatio);
|
||||||
|
@ -194,6 +184,9 @@ export class ChunkUploader {
|
||||||
err: `failed to get upload status: ${uploadStatusResp.statusText}`,
|
err: `failed to get upload status: ${uploadStatusResp.statusText}`,
|
||||||
};
|
};
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
this.chunkLen = Math.ceil(this.chunkLen * speedDownRatio);
|
||||||
|
await this.backOff();
|
||||||
|
|
||||||
return {
|
return {
|
||||||
filePath,
|
filePath,
|
||||||
uploaded: uploaded,
|
uploaded: uploaded,
|
||||||
|
|
|
@ -4,8 +4,8 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"github.com/ihexxa/quickshare/src/golimiter"
|
|
||||||
"github.com/ihexxa/quickshare/src/db/userstore"
|
"github.com/ihexxa/quickshare/src/db/userstore"
|
||||||
|
"github.com/ihexxa/quickshare/src/golimiter"
|
||||||
)
|
)
|
||||||
|
|
||||||
const cacheSizeLimit = 1024
|
const cacheSizeLimit = 1024
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue