mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
judge: add retry to postFile
This commit is contained in:
1 file changed
+11
-2
@@ -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) {
|
||||||
|
|||||||
Reference in new issue
Block a user