diff --git a/packages/hydrojudge/src/hosts/hydro.ts b/packages/hydrojudge/src/hosts/hydro.ts index 6c75a5fed..c50295a96 100644 --- a/packages/hydrojudge/src/hosts/hydro.ts +++ b/packages/hydrojudge/src/hosts/hydro.ts @@ -65,6 +65,10 @@ export default class Hydro implements Session { }); if (!res.body.links) throw new FormatError('problem not exist'); const queue = new PQueue({ concurrency: 10 }); + let error = null; + queue.on('error', (e) => { + error = e; + }); for (const name in res.body.links) { queue.add(async () => { if (name.includes('/')) await fs.ensureDir(path.dirname(files[name])); @@ -73,6 +77,7 @@ export default class Hydro implements Session { }); } await queue.onIdle(); + if (error) throw error; return null; } diff --git a/packages/hydrooj/src/handler/judge.ts b/packages/hydrooj/src/handler/judge.ts index 5b89fc664..937f2e8a6 100644 --- a/packages/hydrooj/src/handler/judge.ts +++ b/packages/hydrooj/src/handler/judge.ts @@ -154,8 +154,10 @@ export class JudgeResultCallbackContext { } const rdoc = await record.update(this.task.domainId, new ObjectId(this.task.rid as string), $set, $push, $unset); - if (rdoc) bus.broadcast('record/change', rdoc, null, null, body); // trigger a full update - await JudgeResultCallbackContext.postJudge(rdoc, this); + if (rdoc) { + bus.broadcast('record/change', rdoc, null, null, body); // trigger a full update + await JudgeResultCallbackContext.postJudge(rdoc, this); + } this.resolve(rdoc); } @@ -165,8 +167,10 @@ export class JudgeResultCallbackContext { $set.judgeAt = new Date(); $set.judger = body.judger ?? 1; const rdoc = await record.update(domainId, rid, $set, $push, $unset); - if (rdoc) app.broadcast('record/change', rdoc, null, null, body); // trigger a full update - await JudgeResultCallbackContext.postJudge(rdoc); + if (rdoc) { + app.broadcast('record/change', rdoc, null, null, body); // trigger a full update + await JudgeResultCallbackContext.postJudge(rdoc); + } } end(body?: Partial) { diff --git a/packages/hydrooj/src/model/task.ts b/packages/hydrooj/src/model/task.ts index 879aa5747..a83072427 100644 --- a/packages/hydrooj/src/model/task.ts +++ b/packages/hydrooj/src/model/task.ts @@ -54,16 +54,13 @@ export class Consumer { }); continue; } - // eslint-disable-next-line no-await-in-loop - const res = await getFirst(this.filter); + const res = await getFirst(this.filter); // eslint-disable-line no-await-in-loop if (!res) { - let timeout: NodeJS.Timeout = null; // eslint-disable-next-line no-await-in-loop - await new Promise((resolve) => { - timeout = setTimeout(resolve, 1000 / (this.concurrency - this.processing.size)); - this.notify = resolve; - }); - clearTimeout(timeout); + await Promise.race([ + new Promise((resolve) => { this.notify = resolve; }), + sleep(1000 / (this.concurrency - this.processing.size)), + ]); continue; } this.processing.add(res);