Skip to content

Commit f0025b2

Browse files
authored
Thuai9 config (#1788)
* start thuai9 * fix cpp compile output path * enable docker cron * disable envoy * fixed file name * enable debug log
1 parent 1314788 commit f0025b2

3 files changed

Lines changed: 56 additions & 8 deletions

File tree

src/routes/arena.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,7 @@ router.post("/create", authenticate(), async (req, res) => {
210210
return Promise.resolve(true);
211211
})
212212
.catch((err) => {
213+
console.error("Error while creating code source directory", err);
213214
console.log(`Mkdir ${team_id} failed: ${err}`);
214215
return Promise.resolve(false);
215216
});
@@ -232,7 +233,8 @@ router.post("/create", authenticate(), async (req, res) => {
232233
.then(() => {
233234
return true;
234235
})
235-
.catch(() => {
236+
.catch((err) => {
237+
console.error("Error while checking code file existence", err);
236238
return false;
237239
});
238240
});
@@ -281,6 +283,7 @@ router.post("/create", authenticate(), async (req, res) => {
281283
return Promise.resolve(true);
282284
})
283285
.catch((err) => {
286+
console.error("Error while downloading team code file", err);
284287
console.log(`Download ${code_file_name} failed: ${err}`);
285288
return Promise.resolve(false);
286289
});
@@ -302,6 +305,7 @@ router.post("/create", authenticate(), async (req, res) => {
302305
return files.length;
303306
})
304307
.catch((err) => {
308+
console.error("Error while reading map directory", err);
305309
console.log(`Read ${map_id} files failed: ${err}`);
306310
return -1;
307311
});
@@ -325,6 +329,7 @@ router.post("/create", authenticate(), async (req, res) => {
325329
cos,
326330
config,
327331
).catch((err) => {
332+
console.error("Error while downloading map file", err);
328333
console.log(`Download ${map_id}.txt failed: ${err}`);
329334
// return res.status(500).send("500 Internal Server Error: Map download failed");
330335
return;
@@ -340,6 +345,7 @@ router.post("/create", authenticate(), async (req, res) => {
340345
return files.length;
341346
})
342347
.catch((err) => {
348+
console.error("Error while reading team code directory", err);
343349
console.log(`Read ${team_id} files failed: ${err}`);
344350
return -1;
345351
});
@@ -392,6 +398,7 @@ router.post("/create", authenticate(), async (req, res) => {
392398
return Promise.resolve(true);
393399
})
394400
.catch((err) => {
401+
console.error("Error while cleaning old code files", err);
395402
console.log(`Clean ${team_id} files failed: ${err}`);
396403
return Promise.resolve(false);
397404
});
@@ -455,6 +462,7 @@ router.post("/create", authenticate(), async (req, res) => {
455462
return Promise.resolve(true);
456463
})
457464
.catch((err) => {
465+
console.error("Error while linking arena runtime code", err);
458466
console.log(`Copy ${code_file_name} failed: ${err}`);
459467
return Promise.resolve(false);
460468
});
@@ -624,6 +632,7 @@ router.post("/finish", async (req, res) => {
624632
return Promise.resolve(true);
625633
})
626634
.catch((err) => {
635+
console.error("Error while uploading arena output file", err);
627636
console.log(`Upload ${filename} failed: ${err}`);
628637
return Promise.resolve(false);
629638
});
@@ -654,6 +663,7 @@ router.post("/finish", async (req, res) => {
654663
return true;
655664
})
656665
.catch((err) => {
666+
console.error("Error while uploading arena extra file", err);
657667
console.log(`Upload ${extraFileName} failed: ${err}`);
658668
return false;
659669
});
@@ -667,11 +677,13 @@ router.post("/finish", async (req, res) => {
667677
console.log("Extra files uploaded!");
668678
}
669679
} catch (err) {
680+
console.error("Error while uploading arena finish artifacts", err);
670681
return res
671682
.status(500)
672683
.send("500 Internal Server Error: Upload files failed. " + err);
673684
}
674685
} catch (err) {
686+
console.error("Error while checking arena output directory", err);
675687
console.log("No output files found!");
676688
} finally {
677689
const dir_to_remove = `${base_directory}/${contest_name}/arena/${room_id}`;
@@ -720,6 +732,7 @@ router.get("/playback/:room_id", async (req, res) => {
720732
utils.deleteAllFilesInDir(`${base_directory}/temp/${room_id}`);
721733
});
722734
} catch (err) {
735+
console.error("Error while fetching arena playback", err);
723736
console.log(err);
724737
return res.status(404).send("404 Not Found: Playback not found");
725738
}

src/routes/code.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ const waitForFile = async (
2020
await fs.access(filePath);
2121
return true;
2222
} catch (err) {
23+
console.error("Error while waiting for file access", err);
2324
await new Promise((resolve) => setTimeout(resolve, interval));
2425
}
2526
}
@@ -66,6 +67,7 @@ router.put("/upload", async (req, res) => {
6667
}
6768
return res.status(200).send("200 OK: Upload success");
6869
} catch (err) {
70+
console.error("Error in upload code route", err);
6971
console.log("error in upload code: ", err);
7072
return res.status(500).send(`500 Internal Server Error: ${err}`);
7173
}
@@ -180,6 +182,7 @@ router.post("/compile-start", authenticate(), async (req, res) => {
180182
);
181183
await COS.downloadObject(key, outputPath, cos, config);
182184
} catch (err) {
185+
console.error("Error in compile-start code download", err);
183186
return res
184187
.status(500)
185188
.send("500 Internal Server Error: Download code failed. " + err);
@@ -258,11 +261,13 @@ router.post("/compile-start", authenticate(), async (req, res) => {
258261
return res.status(200).send("200 OK: Create container success");
259262
}
260263
} catch (err) {
264+
console.error("Error in compile-start container creation", err);
261265
return res
262266
.status(500)
263267
.send("500 Internal Server Error: Create container failed. " + err);
264268
}
265269
} catch (err) {
270+
console.error("Error in compile-start handler", err);
266271
return res
267272
.status(500)
268273
.send("500 Internal Server Error: Unknown error. " + err);
@@ -341,10 +346,12 @@ router.post("/compile-finish", async (req, res) => {
341346
await fs.rename(localFilePath, `${destinationDir}/${code_id}`);
342347
await fs.chmod(`${destinationDir}/${code_id}`, 0o755);
343348
} catch (err) {
349+
console.error("Error while moving compiled file", err);
344350
console.log("Move file failed: ", err);
345351
}
346352
}
347353
} catch (err) {
354+
console.error("Error in uploading files: ", err);
348355
return res
349356
.status(500)
350357
.send("500 Internal Server Error: Upload files failed. " + err);
@@ -353,6 +360,7 @@ router.post("/compile-finish", async (req, res) => {
353360
try {
354361
await ContHasFunc.update_compile_status(code_id, compile_status);
355362
} catch (err) {
363+
console.error("Error while updating compile status", err);
356364
return res
357365
.status(500)
358366
.send(
@@ -365,6 +373,7 @@ router.post("/compile-finish", async (req, res) => {
365373
`${base_directory}/${contest_name}/code/${team_id}/${code_id}`,
366374
);
367375
} catch (err) {
376+
console.error("Error while deleting compile temp files", err);
368377
return res
369378
.status(500)
370379
.send("500 Internal Server Error: Delete files failed. " + err);
@@ -373,6 +382,7 @@ router.post("/compile-finish", async (req, res) => {
373382
return res.status(200).send("200 OK: Update compile status success");
374383
});
375384
} catch (err) {
385+
console.error("Error in compile-finish handler", err);
376386
return res
377387
.status(500)
378388
.send("500 Internal Server Error: Unknown error. " + err);

src/routes/competition.ts

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,7 @@ router.post("/start-all", authenticate(), async (req, res) => {
173173
return Promise.resolve(true);
174174
})
175175
.catch((err) => {
176+
console.error("Error while creating code source directory", err);
176177
console.log(`Mkdir ${team_id} failed: ${err}`);
177178
return Promise.resolve(false);
178179
});
@@ -197,7 +198,8 @@ router.post("/start-all", authenticate(), async (req, res) => {
197198
.then(() => {
198199
return true;
199200
})
200-
.catch(() => {
201+
.catch((err) => {
202+
console.error("Error while checking code file existence", err);
201203
return false;
202204
});
203205
});
@@ -248,6 +250,7 @@ router.post("/start-all", authenticate(), async (req, res) => {
248250
return Promise.resolve(true);
249251
})
250252
.catch((err) => {
253+
console.error("Error while downloading team code file", err);
251254
console.log(`Download ${code_file_name} failed: ${err}`);
252255
return Promise.resolve(false);
253256
});
@@ -267,6 +270,7 @@ router.post("/start-all", authenticate(), async (req, res) => {
267270
return files.length;
268271
})
269272
.catch((err) => {
273+
console.error("Error while reading map directory", err);
270274
console.log(`Read ${map_id} files failed: ${err}`);
271275
return -1;
272276
});
@@ -288,6 +292,7 @@ router.post("/start-all", authenticate(), async (req, res) => {
288292
cos,
289293
config,
290294
).catch((err) => {
295+
console.error("Error while downloading map file", err);
291296
console.log(`Download ${map_id}.txt failed: ${err}`);
292297
// return res.status(500).send("500 Internal Server Error: Map download failed");
293298
return;
@@ -440,6 +445,7 @@ router.post("/start-all", authenticate(), async (req, res) => {
440445
return Promise.resolve(true);
441446
})
442447
.catch((err) => {
448+
console.error("Error while linking competition runtime code", err);
443449
console.log(`Copy ${code_file_name} failed: ${err}`);
444450
return Promise.resolve(false);
445451
});
@@ -467,6 +473,7 @@ router.post("/start-all", authenticate(), async (req, res) => {
467473
return Promise.resolve(true);
468474
})
469475
.catch((err: any) => {
476+
console.error("Error while starting one competition room", err);
470477
console.log(`Start competition failed: ${err}`);
471478
return Promise.resolve(false);
472479
});
@@ -659,6 +666,7 @@ router.post("/start-one", authenticate(), async (req, res) => {
659666
return Promise.resolve(true);
660667
})
661668
.catch((err) => {
669+
console.error("Error while creating code source directory", err);
662670
console.log(`Mkdir ${team_id} failed: ${err}`);
663671
return Promise.resolve(false);
664672
});
@@ -681,7 +689,8 @@ router.post("/start-one", authenticate(), async (req, res) => {
681689
.then(() => {
682690
return true;
683691
})
684-
.catch(() => {
692+
.catch((err) => {
693+
console.error("Error while checking code file existence", err);
685694
return false;
686695
});
687696
});
@@ -730,6 +739,7 @@ router.post("/start-one", authenticate(), async (req, res) => {
730739
return Promise.resolve(true);
731740
})
732741
.catch((err) => {
742+
console.error("Error while downloading team code file", err);
733743
console.log(`Download ${code_file_name} failed: ${err}`);
734744
return Promise.resolve(false);
735745
});
@@ -751,6 +761,7 @@ router.post("/start-one", authenticate(), async (req, res) => {
751761
return files.length;
752762
})
753763
.catch((err) => {
764+
console.error("Error while reading map directory", err);
754765
console.log(`Read ${map_id} files failed: ${err}`);
755766
return -1;
756767
});
@@ -774,6 +785,7 @@ router.post("/start-one", authenticate(), async (req, res) => {
774785
cos,
775786
config,
776787
).catch((err) => {
788+
console.error("Error while downloading map file", err);
777789
console.log(`Download ${map_id}.txt failed: ${err}`);
778790
// return res.status(500).send("500 Internal Server Error: Map download failed");
779791
return;
@@ -788,6 +800,7 @@ router.post("/start-one", authenticate(), async (req, res) => {
788800
return room_id ? Array.from(new Set(room_id)) : [];
789801
})
790802
.catch((err: any) => {
803+
console.error("Error while querying room ids", err);
791804
console.log(`Get room id failed: ${err}`);
792805
return [];
793806
});
@@ -831,6 +844,7 @@ router.post("/start-one", authenticate(), async (req, res) => {
831844
);
832845
})
833846
.catch((err: any) => {
847+
console.error("Error while deleting old competition room", err);
834848
console.log(`Delete room failed: ${err}`);
835849
return Promise.resolve(false);
836850
});
@@ -893,6 +907,7 @@ router.post("/start-one", authenticate(), async (req, res) => {
893907
return Promise.resolve(true);
894908
})
895909
.catch((err) => {
910+
console.error("Error while linking competition runtime code", err);
896911
console.log(`Copy ${code_file_name} failed: ${err}`);
897912
return Promise.resolve(false);
898913
});
@@ -1069,6 +1084,7 @@ router.post("/finish-one", async (req, res) => {
10691084
return Promise.resolve(true);
10701085
})
10711086
.catch((err) => {
1087+
console.error("Error while uploading competition output file", err);
10721088
console.log(`Upload ${filename} failed: ${err}`);
10731089
return Promise.resolve(false);
10741090
});
@@ -1099,6 +1115,7 @@ router.post("/finish-one", async (req, res) => {
10991115
return true;
11001116
})
11011117
.catch((err) => {
1118+
console.error("Error while uploading competition extra file", err);
11021119
console.log(`Upload ${extraFileName} failed: ${err}`);
11031120
return false;
11041121
});
@@ -1112,11 +1129,13 @@ router.post("/finish-one", async (req, res) => {
11121129
console.log("Extra files uploaded!");
11131130
}
11141131
} catch (err) {
1132+
console.error("Error while uploading competition finish artifacts", err);
11151133
return res
11161134
.status(500)
11171135
.send("500 Internal Server Error: Delete files failed. " + err);
11181136
}
11191137
} catch (err) {
1138+
console.error("Error while checking competition output directory", err);
11201139
console.log("No output files found!");
11211140
} finally {
11221141
const dir_to_remove = `${base_directory}/${contest_name}/competition/${room_id}`;
@@ -1165,6 +1184,7 @@ router.get("/playback/:room_id", async (req, res) => {
11651184
utils.deleteAllFilesInDir(`${base_directory}/temp/${room_id}`);
11661185
});
11671186
} catch (err) {
1187+
console.error("Error while fetching competition playback", err);
11681188
console.log(err);
11691189
return res.status(404).send("404 Not Found: Playback not found");
11701190
}
@@ -1200,7 +1220,8 @@ router.post("/add_team_software_code", authenticate(), async (req, res) => {
12001220
// Validate URL format
12011221
try {
12021222
new URL(code_url);
1203-
} catch {
1223+
} catch (err) {
1224+
console.error("Error while validating software code URL", err);
12041225
return res
12051226
.status(400)
12061227
.json({ error: "400 Bad Request: Invalid URL format" });
@@ -1265,7 +1286,8 @@ router.post("/update_team_software_code", authenticate(), async (req, res) => {
12651286
// Validate URL format
12661287
try {
12671288
new URL(code_url);
1268-
} catch {
1289+
} catch (err) {
1290+
console.error("Error while validating software code URL", err);
12691291
return res
12701292
.status(400)
12711293
.json({ error: "400 Bad Request: Invalid URL format" });
@@ -1390,7 +1412,8 @@ router.post("/update_team_software_final", authenticate(), async (req, res) => {
13901412
// Validate URL format
13911413
try {
13921414
new URL(code_url);
1393-
} catch {
1415+
} catch (err) {
1416+
console.error("Error while validating software final URL", err);
13941417
return res
13951418
.status(400)
13961419
.json({ error: "400 Bad Request: Invalid URL format" });
@@ -1514,7 +1537,8 @@ router.post("/add_team_software_final", authenticate(), async (req, res) => {
15141537
// Validate URL format
15151538
try {
15161539
new URL(code_url);
1517-
} catch {
1540+
} catch (err) {
1541+
console.error("Error while validating software final URL", err);
15181542
return res
15191543
.status(400)
15201544
.json({ error: "400 Bad Request: Invalid URL format" });
@@ -1614,7 +1638,8 @@ const isValidUrl = (value: string) => {
16141638
try {
16151639
new URL(value);
16161640
return true;
1617-
} catch {
1641+
} catch (err) {
1642+
console.error("Error while validating URL string", err);
16181643
return false;
16191644
}
16201645
};

0 commit comments

Comments
 (0)