mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-19 17:38:19 +08:00
core: remove rdoc in judge callback
This commit is contained in:
4 files changed
+19
-31
No files matched your search
@@ -28,7 +28,7 @@ const session = {
|
|||||||
data.rid = t.rid as any;
|
data.rid = t.rid as any;
|
||||||
const rdoc = await RecordModel.get(new ObjectId(t.rid));
|
const rdoc = await RecordModel.get(new ObjectId(t.rid));
|
||||||
if (data.case) data.case.message ||= '';
|
if (data.case) data.case.message ||= '';
|
||||||
next({ ...data, rdoc });
|
next({ ...data, domainId: rdoc.domainId });
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
getEnd(t: Context) {
|
getEnd(t: Context) {
|
||||||
@@ -37,7 +37,7 @@ const session = {
|
|||||||
data.rid = t.rid as any;
|
data.rid = t.rid as any;
|
||||||
const rdoc = await RecordModel.get(new ObjectId(t.rid));
|
const rdoc = await RecordModel.get(new ObjectId(t.rid));
|
||||||
logger.info('End: status=%d score=%d time=%dms memory=%dkb', data.status, data.score, data.time, data.memory);
|
logger.info('End: status=%d score=%d time=%dms memory=%dkb', data.status, data.score, data.time, data.memory);
|
||||||
end({ ...data, rdoc });
|
end({ ...data, domainId: rdoc.domainId });
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
getLang(lang: string, doThrow = true) {
|
getLang(lang: string, doThrow = true) {
|
||||||
|
|||||||
@@ -166,6 +166,8 @@ export default class Hydro implements Session {
|
|||||||
if (performanceMode && data.case && !data.compilerText && !data.message) {
|
if (performanceMode && data.case && !data.compilerText && !data.message) {
|
||||||
t.callbackCache ||= [];
|
t.callbackCache ||= [];
|
||||||
t.callbackCache.push(data.case);
|
t.callbackCache.push(data.case);
|
||||||
|
// TODO use rate-limited send
|
||||||
|
// FIXME handle fields like score, time, memory, etc
|
||||||
} else {
|
} else {
|
||||||
this.send(t.request.rid, 'next', data);
|
this.send(t.request.rid, 'next', data);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -57,5 +57,10 @@ export const judge = async (ctx: JudgeTask) => {
|
|||||||
}
|
}
|
||||||
ctx.stat.done = new Date();
|
ctx.stat.done = new Date();
|
||||||
if (process.env.DEV) ctx.next({ message: JSON.stringify(ctx.stat) });
|
if (process.env.DEV) ctx.next({ message: JSON.stringify(ctx.stat) });
|
||||||
ctx.end({ status });
|
ctx.end({
|
||||||
|
status,
|
||||||
|
time: Math.floor(time * 1000000) / 1000000,
|
||||||
|
memory,
|
||||||
|
score: status === STATUS.STATUS_ACCEPTED ? 100 : 0,
|
||||||
|
});
|
||||||
};
|
};
|
||||||
@@ -41,24 +41,20 @@ function parseCaseResult(body: TestCase): Required<TestCase> {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
function processPayload(rdoc: RecordDoc, body: Partial<JudgeResultBody>) {
|
function processPayload(body: Partial<JudgeResultBody>) {
|
||||||
const $set: Partial<RecordDoc> = {};
|
const $set: Partial<RecordDoc> = {};
|
||||||
const $push: any = {};
|
const $push: any = {};
|
||||||
if (body.cases?.length) {
|
if (body.cases?.length) {
|
||||||
const c = body.cases.map(parseCaseResult);
|
const c = body.cases.map(parseCaseResult);
|
||||||
rdoc.testCases.push(...c);
|
|
||||||
$push.testCases = { $each: c };
|
$push.testCases = { $each: c };
|
||||||
} else if (body.case) {
|
} else if (body.case) {
|
||||||
const c = parseCaseResult(body.case);
|
const c = parseCaseResult(body.case);
|
||||||
rdoc.testCases.push(c);
|
|
||||||
$push.testCases = c;
|
$push.testCases = c;
|
||||||
}
|
}
|
||||||
if (body.message) {
|
if (body.message) {
|
||||||
rdoc.judgeTexts.push(body.message);
|
|
||||||
$push.judgeTexts = body.message;
|
$push.judgeTexts = body.message;
|
||||||
}
|
}
|
||||||
if (body.compilerText) {
|
if (body.compilerText) {
|
||||||
rdoc.compilerTexts.push(body.compilerText);
|
|
||||||
$push.compilerTexts = body.compilerText;
|
$push.compilerTexts = body.compilerText;
|
||||||
}
|
}
|
||||||
if (body.status) $set.status = body.status;
|
if (body.status) $set.status = body.status;
|
||||||
@@ -70,17 +66,10 @@ function processPayload(rdoc: RecordDoc, body: Partial<JudgeResultBody>) {
|
|||||||
return { $set, $push };
|
return { $set, $push };
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function next(body: Partial<JudgeResultBody> & { rdoc: RecordDoc }) {
|
export async function next(body: Partial<JudgeResultBody>) {
|
||||||
body.rid = new ObjectId(body.rid);
|
body.rid = new ObjectId(body.rid);
|
||||||
let rdoc = body.rdoc;
|
const { $set, $push } = processPayload(body);
|
||||||
if (!rdoc) {
|
const rdoc = await record.update(body.domainId, body.rid, $set, $push, {}, body.addProgress ? { progress: body.addProgress } : {});
|
||||||
logger.warn('Next function without rdoc is deprecated.');
|
|
||||||
console.trace();
|
|
||||||
rdoc = await record.get(body.rid);
|
|
||||||
if (!rdoc) return null;
|
|
||||||
}
|
|
||||||
const { $set, $push } = processPayload(rdoc, body);
|
|
||||||
rdoc = await record.update(rdoc.domainId, body.rid, $set, $push, {}, body.addProgress ? { progress: body.addProgress } : {});
|
|
||||||
bus.broadcast('record/change', rdoc, $set, $push, body);
|
bus.broadcast('record/change', rdoc, $set, $push, body);
|
||||||
return rdoc;
|
return rdoc;
|
||||||
}
|
}
|
||||||
@@ -137,7 +126,6 @@ export async function postJudge(rdoc: RecordDoc) {
|
|||||||
domainId: rdoc.domainId,
|
domainId: rdoc.domainId,
|
||||||
key: 'next',
|
key: 'next',
|
||||||
message: { message: 'Unable to apply hack: {0}', params: [e.message] },
|
message: { message: 'Unable to apply hack: {0}', params: [e.message] },
|
||||||
rdoc,
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -145,21 +133,14 @@ export async function postJudge(rdoc: RecordDoc) {
|
|||||||
await bus.parallel('record/judge', rdoc, updated);
|
await bus.parallel('record/judge', rdoc, updated);
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function end(body: Partial<JudgeResultBody> & { rdoc: RecordDoc }) {
|
export async function end(body: Partial<JudgeResultBody>) {
|
||||||
body.rid = new ObjectId(body.rid);
|
body.rid = new ObjectId(body.rid);
|
||||||
let rdoc = body.rdoc;
|
const { $set, $push } = processPayload(body);
|
||||||
if (!rdoc) {
|
|
||||||
logger.warn('End function without rdoc is deprecated.');
|
|
||||||
console.trace();
|
|
||||||
rdoc = await record.get(body.rid);
|
|
||||||
if (!rdoc) return null;
|
|
||||||
}
|
|
||||||
const { $set, $push } = processPayload(rdoc, body);
|
|
||||||
const $unset: any = { progress: '' };
|
const $unset: any = { progress: '' };
|
||||||
$set.judgeAt = new Date();
|
$set.judgeAt = new Date();
|
||||||
$set.judger = body.judger ?? 1;
|
$set.judger = body.judger ?? 1;
|
||||||
await sleep(100); // Make sure that all 'next' event already triggered
|
await sleep(100); // Make sure that all 'next' event already triggered
|
||||||
rdoc = await record.update(rdoc.domainId, body.rid, $set, $push, $unset);
|
let rdoc = await record.update(body.domainId, body.rid, $set, $push, $unset);
|
||||||
await postJudge(rdoc);
|
await postJudge(rdoc);
|
||||||
rdoc = await record.get(body.rid);
|
rdoc = await record.get(body.rid);
|
||||||
bus.broadcast('record/change', rdoc, null, null, body); // trigger a full update
|
bus.broadcast('record/change', rdoc, null, null, body); // trigger a full update
|
||||||
@@ -283,9 +264,9 @@ class JudgeConnectionHandler extends ConnectionHandler {
|
|||||||
if (['next', 'end'].includes(msg.key)) {
|
if (['next', 'end'].includes(msg.key)) {
|
||||||
const rdoc = this.rdocs[msg.rid];
|
const rdoc = this.rdocs[msg.rid];
|
||||||
if (!rdoc) return;
|
if (!rdoc) return;
|
||||||
if (msg.key === 'next') await next({ ...msg, rdoc });
|
if (msg.key === 'next') await next({ ...message, domainId: rdoc.domainId });
|
||||||
if (msg.key === 'end') {
|
if (msg.key === 'end') {
|
||||||
if (!msg.nop) await end({ judger: this.user._id, ...msg, rdoc }).catch((e) => logger.error(e));
|
if (!msg.nop) await end({ judger: this.user._id, ...msg, domainId: rdoc.domainId }).catch((e) => logger.error(e));
|
||||||
this.processing = this.processing.filter((t) => t.rid.toHexString() !== msg.rid);
|
this.processing = this.processing.filter((t) => t.rid.toHexString() !== msg.rid);
|
||||||
delete this.rdocs[msg.rid];
|
delete this.rdocs[msg.rid];
|
||||||
await this.newTask();
|
await this.newTask();
|
||||||
|
|||||||
Reference in new issue
Block a user