judge: 修复使用vj4后端时测试点显示异常的问题

This commit is contained in:
undefined committed 2020-10-27 22:19:39 +08:00
1 parent 59b38130b6
commit 3c9161292a
2 files changed
+46 -42

No files matched your search

+1 -1
View File
@@ -1,7 +1,7 @@
{ {
"name": "@hydrooj/hydrojudge", "name": "@hydrooj/hydrojudge",
"bin": "bin/hydrojudge.js", "bin": "bin/hydrojudge.js",
"version": "2.1.3", "version": "2.1.4",
"main": "package.json", "main": "package.json",
"author": "masnn", "author": "masnn",
"dependencies": { "dependencies": {
+45 -41
View File
@@ -38,10 +38,6 @@ class JudgeTask {
code: string; code: string;
next: (data: any, id?: number) => void;
end: (data: any) => void;
tmpdir: string; tmpdir: string;
clean: Function[]; clean: Function[];
@@ -50,6 +46,10 @@ class JudgeTask {
config: any; config: any;
nextId = 1;
nextWaiting = [];
constructor(session, request, ws: WebSocket) { constructor(session, request, ws: WebSocket) {
this.stat = {}; this.stat = {};
this.stat.receive = new Date(); this.stat.receive = new Date();
@@ -60,6 +60,8 @@ class JudgeTask {
} }
async handle() { async handle() {
this.next = this.next.bind(this);
this.end = this.end.bind(this);
this.stat.handle = new Date(); this.stat.handle = new Date();
this.tag = this.request.tag; this.tag = this.request.tag;
this.type = this.request.type; this.type = this.request.type;
@@ -68,8 +70,6 @@ class JudgeTask {
this.rid = this.request.rid; this.rid = this.request.rid;
this.lang = this.request.lang; this.lang = this.request.lang;
this.code = this.request.code; this.code = this.request.code;
this.next = this.getNext(this);
this.end = this.getEnd(this.ws, this.tag);
this.tmpdir = path.resolve(TEMP_DIR, 'tmp', this.host, this.rid); this.tmpdir = path.resolve(TEMP_DIR, 'tmp', this.host, this.rid);
this.clean = []; this.clean = [];
fs.ensureDirSync(this.tmpdir); fs.ensureDirSync(this.tmpdir);
@@ -106,9 +106,7 @@ class JudgeTask {
async doSubmission() { async doSubmission() {
this.stat.cache_start = new Date(); this.stat.cache_start = new Date();
this.folder = await this.session.cacheOpen( this.folder = await this.session.cacheOpen(this.domain_id, this.pid, this.next);
this.domain_id, this.pid, this.next.bind(this),
);
this.stat.read_cases = new Date(); this.stat.read_cases = new Date();
this.config = await readCases( this.config = await readCases(
this.folder, this.folder,
@@ -130,40 +128,46 @@ class JudgeTask {
await judge[this.config.type || 'default'].judge(this); await judge[this.config.type || 'default'].judge(this);
} }
getNext(that) { // eslint-disable-line class-methods-use-this next(data, id?: number) {
that.nextId = 1; if (data.message !== undefined) {
that.nextWaiting = []; data.judge_text = data.message;
return (data, id) => { delete data.message;
data.key = 'next'; }
data.tag = that.tag; if (data.case?.message !== undefined) {
if (id) { data.case.judge_text = data.case.message;
if (id === that.nextId) { delete data.case.message;
that.ws.send(JSON.stringify(data)); }
that.nextId++; data.key = 'next';
let t = true; data.tag = this.tag;
while (t) { if (id) {
t = false; if (id === this.nextId) {
for (const i in that.nextWaiting) { this.ws.send(JSON.stringify(data));
if (that.nextId === that.nextWaiting[i].id) { this.nextId++;
that.ws.send(JSON.stringify(that.nextWaiting[i].data)); let t = true;
that.nextId++; while (t) {
that.nextWaiting.splice(i, 1); t = false;
t = true; for (const i in this.nextWaiting) {
} if (this.nextId === this.nextWaiting[i].id) {
this.ws.send(JSON.stringify(this.nextWaiting[i].data));
this.nextId++;
this.nextWaiting.splice(+i, 1);
t = true;
} }
} }
} else that.nextWaiting.push({ data, id }); }
} else that.ws.send(JSON.stringify(data)); } else this.nextWaiting.push({ data, id });
}; } else this.ws.send(JSON.stringify(data));
} }
getEnd(ws, tag) { // eslint-disable-line class-methods-use-this end(data) {
return (data) => { if (data.message !== undefined) {
data.key = 'end'; data.judge_text = data.message;
data.tag = tag; delete data.message;
log.info('Status=%d Score=%s Time=%dms Memory=%dkb', data.status, data.score, data.time_ms, data.memory_kb); }
ws.send(JSON.stringify(data)); data.key = 'end';
}; data.tag = this.tag;
log.info('Status=%d Score=%s Time=%dms Memory=%dkb', data.status, data.score, data.time_ms, data.memory_kb);
this.ws.send(JSON.stringify(data));
} }
} }
@@ -190,8 +194,8 @@ export default class VJ4 {
} }
async problemDataVersion(domainId: string, pid: string, retry = 3) { async problemDataVersion(domainId: string, pid: string, retry = 3) {
let location; let location: string;
let err; let err: Error;
await this.ensureLogin(); await this.ensureLogin();
try { try {
await this.axios.get(`d/${domainId}/p/${pid}/data`, { maxRedirects: 0 }); await this.axios.get(`d/${domainId}/p/${pid}/data`, { maxRedirects: 0 });