From 6bb7945fbfd81ba23affff680c09f7f65183491b Mon Sep 17 00:00:00 2001 From: Karol Wypchlo Date: Tue, 3 Aug 2021 16:01:17 +0200 Subject: [PATCH] multiply delay on every subsequent retry --- .../website/src/components/Uploader/UploaderElement.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/packages/website/src/components/Uploader/UploaderElement.js b/packages/website/src/components/Uploader/UploaderElement.js index f4842c04..86dd2ada 100644 --- a/packages/website/src/components/Uploader/UploaderElement.js +++ b/packages/website/src/components/Uploader/UploaderElement.js @@ -10,8 +10,6 @@ import { useTimeoutFn } from "react-use"; import ms from "ms"; import Link from "../Link"; -const TOO_MANY_REQUESTS_RETRY = ms("5s"); // retry delay after "429: TOO_MANY_REQUESTS" - const getFilePath = (file) => file.webkitRelativePath || file.path || file.name; const getRelativeFilePath = (file) => { @@ -62,6 +60,7 @@ const client = new SkynetClient(process.env.GATSBY_API_URL); export default function UploaderElement({ onUploadStateChange, upload }) { const [copied, setCopied] = React.useState(false); const [, , reset] = useTimeoutFn(() => setCopied(false), ms("3 seconds")); + const [retryTimeout, setRetryTimeout] = React.useState(ms("3 seconds")); // retry delay after "429: TOO_MANY_REQUESTS" const handleCopy = (url) => { copy(url); @@ -102,14 +101,15 @@ export default function UploaderElement({ onUploadStateChange, upload }) { setTimeout(() => { onUploadStateChange(upload.id, { status: "enqueued", startedTime: null }); - }, TOO_MANY_REQUESTS_RETRY); + setRetryTimeout((timeout) => timeout * 2); // increase timeout on next retry + }, retryTimeout); } else { onUploadStateChange(upload.id, { status: "error", error: createUploadErrorMessage(error) }); } } })(); } - }, [onUploadStateChange, upload]); + }, [onUploadStateChange, upload, retryTimeout]); return (
@@ -138,7 +138,7 @@ export default function UploaderElement({ onUploadStateChange, upload }) { )} {upload.status === "error" && upload.error && {upload.error}} {upload.status === "retrying" && ( - Too many parallel requests, retrying in {TOO_MANY_REQUESTS_RETRY / 1000} seconds + Too many parallel requests, retrying in {retryTimeout / 1000} seconds )}