1
0
Fork 1
forked from fedi/mastodon

Gradually increase retry waiting for media processing (#17271)

This commit is contained in:
Jeong Arm 2022-01-10 22:25:08 +09:00 committed by GitHub
parent 3dc0357d9e
commit bc7a8ae6d6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -252,12 +252,15 @@ export function uploadCompose(files) {
if (status === 200) {
dispatch(uploadComposeSuccess(data, f));
} else if (status === 202) {
let tryCount = 1;
const poll = () => {
api(getState).get(`/api/v1/media/${data.id}`).then(response => {
if (response.status === 200) {
dispatch(uploadComposeSuccess(response.data, f));
} else if (response.status === 206) {
setTimeout(() => poll(), 1000);
let retryAfter = (Math.log2(tryCount) || 1) * 1000;
tryCount += 1;
setTimeout(() => poll(), retryAfter);
}
}).catch(error => dispatch(uploadComposeFail(error)));
};