judge: add retry to postFile

This commit is contained in:
undefined committed 2025-01-03 01:03:28 +08:00
1 parent 566ebd9bb2
commit 07165b1d38
1 file changed
+11 -2
+11 -2
View File
@@ -116,11 +116,20 @@ export default class Hydro implements Session {
return target; return target;
} }
async postFile(target: string, filename: string, file: string) { async postFile(target: string, filename: string, file: string, retry = 3) {
try {
await this.post('judge/upload') await this.post('judge/upload')
.field('rid', target) .field('rid', target)
.field('name', filename) .field('name', filename)
.attach('file', fs.createReadStream(file)); .attach('file', await fs.readFile(file));
} catch (e) {
if (!retry) {
log.error('PostFile Fail: %s %s %o', target, filename, e);
throw e;
}
await new Promise((resolve) => { setTimeout(resolve, 1000); });
await this.postFile(target, filename, file, retry - 1);
}
} }
getLang(name: string, doThrow = true) { getLang(name: string, doThrow = true) {