Skip to content

Commit

Permalink
judge: add retry to postFile
Browse files Browse the repository at this point in the history
  • Loading branch information
undefined-moe committed Jan 2, 2025
1 parent 566ebd9 commit 07165b1
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions packages/hydrojudge/src/hosts/hydro.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,11 +116,20 @@ export default class Hydro implements Session {
return target;
}

async postFile(target: string, filename: string, file: string) {
await this.post('judge/upload')
.field('rid', target)
.field('name', filename)
.attach('file', fs.createReadStream(file));
async postFile(target: string, filename: string, file: string, retry = 3) {
try {
await this.post('judge/upload')
.field('rid', target)
.field('name', filename)
.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) {
Expand Down

0 comments on commit 07165b1

Please sign in to comment.