From bf6424f75d5ec77fc541846bf42bd9dd4a17b241 Mon Sep 17 00:00:00 2001 From: qtchaos <72168435+qtchaos@users.noreply.github.com> Date: Sun, 25 Feb 2024 22:04:47 +0200 Subject: [PATCH] feat: run worker tests in parallel with 5 sec cooldown --- src/pages/parts/admin/TMDBTestPart.tsx | 8 ++++---- src/pages/parts/admin/WorkerTestPart.tsx | 20 ++++++++++++++++---- 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/src/pages/parts/admin/TMDBTestPart.tsx b/src/pages/parts/admin/TMDBTestPart.tsx index 00198946..a7f8fa50 100644 --- a/src/pages/parts/admin/TMDBTestPart.tsx +++ b/src/pages/parts/admin/TMDBTestPart.tsx @@ -29,7 +29,7 @@ export function TMDBTestPart() { return setStatus({ hasTested: true, success: false, - errorText: "TMDB api key is not set", + errorText: "TMDB API key is not set", }); } const isJWT = tmdbApiKey.split(".").length > 2; @@ -37,7 +37,7 @@ export function TMDBTestPart() { return setStatus({ hasTested: true, success: false, - errorText: "TMDB api key is not a read only key", + errorText: "TMDB API key is not a read only key", }); } @@ -48,7 +48,7 @@ export function TMDBTestPart() { hasTested: true, success: false, errorText: - "Failed to call tmdb, double check api key and your internet connection", + "Failed to call TMDB, double check API key and your internet connection", }); } @@ -61,7 +61,7 @@ export function TMDBTestPart() { return ( <> - TMDB tests + TMDB test
diff --git a/src/pages/parts/admin/WorkerTestPart.tsx b/src/pages/parts/admin/WorkerTestPart.tsx index e2dd6780..5f8b9853 100644 --- a/src/pages/parts/admin/WorkerTestPart.tsx +++ b/src/pages/parts/admin/WorkerTestPart.tsx @@ -52,14 +52,18 @@ export function WorkerTestPart() { { id: string; status: "error" | "success"; error?: Error }[] >([]); + const [buttonDisabled, setButtonDisabled] = useState(false); + const [testState, runTests] = useAsyncFn(async () => { + setButtonDisabled(true); function updateWorker(id: string, data: (typeof workerState)[number]) { setWorkerState((s) => { return [...s.filter((v) => v.id !== id), data]; }); } setWorkerState([]); - for (const worker of workerList) { + + const workerPromises = workerList.map(async (worker) => { try { if (worker.url.endsWith("/")) { updateWorker(worker.id, { @@ -67,7 +71,7 @@ export function WorkerTestPart() { status: "error", error: new Error("URL ends with slash"), }); - continue; + return; } await singularProxiedFetch( worker.url, @@ -85,7 +89,10 @@ export function WorkerTestPart() { error: err as Error, }); } - } + }); + + await Promise.all(workerPromises); + setTimeout(() => setButtonDisabled(false), 5000); }, [workerList, setWorkerState]); return ( @@ -112,7 +119,12 @@ export function WorkerTestPart() { })}
-