Skip to content

best way to save what you love

web/workers/fetch: retry only when needed & reduce attempts to 3

wukko9cf40549e3c7
diff --git a/web/i18n/en/error/queue.json b/web/i18n/en/error/queue.json
index ea7eb244..d25a118e 100644
--- a/web/i18n/en/error/queue.json
+++ b/web/i18n/en/error/queue.json
@@ -1,8 +1,8 @@
{
"no_final_file": "no final file output",
"worker_didnt_start": "couldn't start a processing worker",
- "generic_error": "processing pipeline crashed, see console for details",
+ "fetch.crashed": "fetch worker crashed, see console for details",
"fetch.bad_response": "couldn't access the file tunnel",
"fetch.no_file_reader": "couldn't write a file to cache",
"fetch.empty_tunnel": "file tunnel is empty, try again",
diff --git a/web/src/lib/task-manager/workers/fetch.ts b/web/src/lib/task-manager/workers/fetch.ts
index 2e6057dd..80de539b 100644
--- a/web/src/lib/task-manager/workers/fetch.ts
+++ b/web/src/lib/task-manager/workers/fetch.ts
@@ -3,20 +3,19 @@ import * as Storage from "$lib/storage";
let attempts = 0;
const fetchFile = async (url: string) => {
- const error = async (code: string) => {
+ const error = async (code: string, retry: boolean = true) => {
attempts++;
- if (attempts <= 5) {
- // try 5 more times before actually failing
+ // try 3 more times before actually failing
+ if (retry && attempts <= 3) {
await fetchFile(url);
} else {
- // if it still fails, then throw an error and quit
self.postMessage({
cobaltFetchWorker: {
error: code,
}
});
- self.close();
+ return self.close();
}
};
@@ -75,7 +74,7 @@ const fetchFile = async (url: string) => {
const file = Storage.retype(await storage.res(), contentType);
if (contentLength && Number(contentLength) !== file.size) {
- return error("queue.fetch.corrupted_file");
+ return error("queue.fetch.corrupted_file", false);
}
self.postMessage({
@@ -86,7 +85,7 @@ const fetchFile = async (url: string) => {
} catch (e) {
console.error("error from the fetch worker:");
console.error(e);
- return error("queue.generic_error");
+ return error("queue.fetch.crashed", false);
}
}