mirror of
https://github.com/movie-web/movie-web.git
synced 2024-11-11 04:35:09 +01:00
feat: run worker tests in parallel with 5 sec cooldown
This commit is contained in:
parent
c6fe62ae8a
commit
bf6424f75d
@ -29,7 +29,7 @@ export function TMDBTestPart() {
|
|||||||
return setStatus({
|
return setStatus({
|
||||||
hasTested: true,
|
hasTested: true,
|
||||||
success: false,
|
success: false,
|
||||||
errorText: "TMDB api key is not set",
|
errorText: "TMDB API key is not set",
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
const isJWT = tmdbApiKey.split(".").length > 2;
|
const isJWT = tmdbApiKey.split(".").length > 2;
|
||||||
@ -37,7 +37,7 @@ export function TMDBTestPart() {
|
|||||||
return setStatus({
|
return setStatus({
|
||||||
hasTested: true,
|
hasTested: true,
|
||||||
success: false,
|
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,
|
hasTested: true,
|
||||||
success: false,
|
success: false,
|
||||||
errorText:
|
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 (
|
return (
|
||||||
<>
|
<>
|
||||||
<Heading2 className="mb-8 mt-12">TMDB tests</Heading2>
|
<Heading2 className="mb-8 mt-12">TMDB test</Heading2>
|
||||||
<Box>
|
<Box>
|
||||||
<div className="flex items-center">
|
<div className="flex items-center">
|
||||||
<div className="flex-1">
|
<div className="flex-1">
|
||||||
|
@ -52,14 +52,18 @@ export function WorkerTestPart() {
|
|||||||
{ id: string; status: "error" | "success"; error?: Error }[]
|
{ id: string; status: "error" | "success"; error?: Error }[]
|
||||||
>([]);
|
>([]);
|
||||||
|
|
||||||
|
const [buttonDisabled, setButtonDisabled] = useState(false);
|
||||||
|
|
||||||
const [testState, runTests] = useAsyncFn(async () => {
|
const [testState, runTests] = useAsyncFn(async () => {
|
||||||
|
setButtonDisabled(true);
|
||||||
function updateWorker(id: string, data: (typeof workerState)[number]) {
|
function updateWorker(id: string, data: (typeof workerState)[number]) {
|
||||||
setWorkerState((s) => {
|
setWorkerState((s) => {
|
||||||
return [...s.filter((v) => v.id !== id), data];
|
return [...s.filter((v) => v.id !== id), data];
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
setWorkerState([]);
|
setWorkerState([]);
|
||||||
for (const worker of workerList) {
|
|
||||||
|
const workerPromises = workerList.map(async (worker) => {
|
||||||
try {
|
try {
|
||||||
if (worker.url.endsWith("/")) {
|
if (worker.url.endsWith("/")) {
|
||||||
updateWorker(worker.id, {
|
updateWorker(worker.id, {
|
||||||
@ -67,7 +71,7 @@ export function WorkerTestPart() {
|
|||||||
status: "error",
|
status: "error",
|
||||||
error: new Error("URL ends with slash"),
|
error: new Error("URL ends with slash"),
|
||||||
});
|
});
|
||||||
continue;
|
return;
|
||||||
}
|
}
|
||||||
await singularProxiedFetch(
|
await singularProxiedFetch(
|
||||||
worker.url,
|
worker.url,
|
||||||
@ -85,7 +89,10 @@ export function WorkerTestPart() {
|
|||||||
error: err as Error,
|
error: err as Error,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
|
|
||||||
|
await Promise.all(workerPromises);
|
||||||
|
setTimeout(() => setButtonDisabled(false), 5000);
|
||||||
}, [workerList, setWorkerState]);
|
}, [workerList, setWorkerState]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@ -112,7 +119,12 @@ export function WorkerTestPart() {
|
|||||||
})}
|
})}
|
||||||
<Divider />
|
<Divider />
|
||||||
<div className="flex justify-end">
|
<div className="flex justify-end">
|
||||||
<Button theme="purple" loading={testState.loading} onClick={runTests}>
|
<Button
|
||||||
|
theme="purple"
|
||||||
|
loading={testState.loading}
|
||||||
|
onClick={buttonDisabled ? undefined : runTests}
|
||||||
|
disabled={buttonDisabled}
|
||||||
|
>
|
||||||
Test workers
|
Test workers
|
||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
|
Loading…
Reference in New Issue
Block a user