judge: bug fixes

This commit is contained in:
undefined committed 2025-09-28 16:13:11 +08:00
1 parent 753f7613e7
commit 40b933e436
3 files changed
+18 -12

No files matched your search

+5
View File
@@ -65,6 +65,10 @@ export default class Hydro implements Session {
}); });
if (!res.body.links) throw new FormatError('problem not exist'); if (!res.body.links) throw new FormatError('problem not exist');
const queue = new PQueue({ concurrency: 10 }); const queue = new PQueue({ concurrency: 10 });
let error = null;
queue.on('error', (e) => {
error = e;
});
for (const name in res.body.links) { for (const name in res.body.links) {
queue.add(async () => { queue.add(async () => {
if (name.includes('/')) await fs.ensureDir(path.dirname(files[name])); if (name.includes('/')) await fs.ensureDir(path.dirname(files[name]));
@@ -73,6 +77,7 @@ export default class Hydro implements Session {
}); });
} }
await queue.onIdle(); await queue.onIdle();
if (error) throw error;
return null; return null;
} }
+8 -4
View File
@@ -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); 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 if (rdoc) {
await JudgeResultCallbackContext.postJudge(rdoc, this); bus.broadcast('record/change', rdoc, null, null, body); // trigger a full update
await JudgeResultCallbackContext.postJudge(rdoc, this);
}
this.resolve(rdoc); this.resolve(rdoc);
} }
@@ -165,8 +167,10 @@ export class JudgeResultCallbackContext {
$set.judgeAt = new Date(); $set.judgeAt = new Date();
$set.judger = body.judger ?? 1; $set.judger = body.judger ?? 1;
const rdoc = await record.update(domainId, rid, $set, $push, $unset); const rdoc = await record.update(domainId, rid, $set, $push, $unset);
if (rdoc) app.broadcast('record/change', rdoc, null, null, body); // trigger a full update if (rdoc) {
await JudgeResultCallbackContext.postJudge(rdoc); app.broadcast('record/change', rdoc, null, null, body); // trigger a full update
await JudgeResultCallbackContext.postJudge(rdoc);
}
} }
end(body?: Partial<JudgeResultBody>) { end(body?: Partial<JudgeResultBody>) {
+5 -8
View File
@@ -54,16 +54,13 @@ export class Consumer {
}); });
continue; continue;
} }
// eslint-disable-next-line no-await-in-loop const res = await getFirst(this.filter); // eslint-disable-line no-await-in-loop
const res = await getFirst(this.filter);
if (!res) { if (!res) {
let timeout: NodeJS.Timeout = null;
// eslint-disable-next-line no-await-in-loop // eslint-disable-next-line no-await-in-loop
await new Promise((resolve) => { await Promise.race([
timeout = setTimeout(resolve, 1000 / (this.concurrency - this.processing.size)); new Promise((resolve) => { this.notify = resolve; }),
this.notify = resolve; sleep(1000 / (this.concurrency - this.processing.size)),
}); ]);
clearTimeout(timeout);
continue; continue;
} }
this.processing.add(res); this.processing.add(res);