Helped solve a bug where it would get stuck
This commit is contained in:
@@ -14,6 +14,10 @@ import {speakingReverseMarking} from "@/utils/score";
|
||||
const db = getFirestore(app);
|
||||
export default withIronSessionApiRoute(handler, sessionOptions);
|
||||
|
||||
function delay(ms: number) {
|
||||
return new Promise((resolve) => setTimeout(resolve, ms));
|
||||
}
|
||||
|
||||
async function handler(req: NextApiRequest, res: NextApiResponse) {
|
||||
if (!req.session.user) {
|
||||
res.status(401).json({ok: false});
|
||||
@@ -38,7 +42,7 @@ async function handler(req: NextApiRequest, res: NextApiResponse) {
|
||||
const backendRequest = await evaluate({answers: [{question: fields.question, answer: path}]});
|
||||
console.log("🌱 - Process complete");
|
||||
|
||||
const correspondingStat = (await getDoc(doc(db, "stats", fields.id))).data() as Stat;
|
||||
const correspondingStat = await getCorrespondingStat(fields.id, 1);
|
||||
|
||||
const solutions = correspondingStat.solutions.map((x) => ({
|
||||
...x,
|
||||
@@ -63,6 +67,15 @@ async function handler(req: NextApiRequest, res: NextApiResponse) {
|
||||
});
|
||||
}
|
||||
|
||||
async function getCorrespondingStat(id: string, index: number): Promise<Stat> {
|
||||
console.log(`🌱 - Try number ${index} - ${id}`);
|
||||
const correspondingStat = await getDoc(doc(db, "stats", id));
|
||||
|
||||
if (correspondingStat.exists()) return {...correspondingStat.data(), id} as Stat;
|
||||
await delay(3 * 10000);
|
||||
return getCorrespondingStat(id, index + 1);
|
||||
}
|
||||
|
||||
async function evaluate(body: {answers: object[]}): Promise<AxiosResponse> {
|
||||
const backendRequest = await axios.post(`${process.env.BACKEND_URL}/speaking_task_3`, body, {
|
||||
headers: {
|
||||
|
||||
Reference in New Issue
Block a user