mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-21 01:46:28 +08:00
core: add controlled rejudge (#969)
Co-authored-by: panda <panda_dtdyy@outlook.com>
This commit is contained in:
1 parent
536c697f4b
commit
466bc984bd
12 files changed
+170
-119
No files matched your search
@@ -4,8 +4,8 @@ import path from 'path';
|
||||
import { fs } from '@hydrooj/utils';
|
||||
import * as sysinfo from '@hydrooj/utils/lib/sysinfo';
|
||||
import {
|
||||
Context as HydroContext, db, JudgeHandler, JudgeResultBody, ObjectId, RecordModel,
|
||||
SettingModel, StorageModel, SystemModel, TaskModel,
|
||||
Context as HydroContext, db, JudgeHandler, JudgeResultCallbackContext,
|
||||
ObjectId, RecordModel, SettingModel, StorageModel, SystemModel, TaskModel,
|
||||
} from 'hydrooj';
|
||||
import { langs } from 'hydrooj/src/model/setting';
|
||||
import { getConfig } from '../config';
|
||||
@@ -32,20 +32,11 @@ const session: Session = {
|
||||
}
|
||||
return null;
|
||||
},
|
||||
getNext(t: Context) {
|
||||
t._callbackAwait ||= Promise.resolve();
|
||||
return (data: Partial<JudgeResultBody>) => {
|
||||
logger.debug('Next: %o', data);
|
||||
if (data.case) data.case.message ||= '';
|
||||
t._callbackAwait = t._callbackAwait.then(() => JudgeHandler.next({ ...data, rid: t.rid, domainId: t.request.domainId }));
|
||||
};
|
||||
},
|
||||
getEnd(t: Context) {
|
||||
t._callbackAwait ||= Promise.resolve();
|
||||
return (data: Partial<JudgeResultBody>) => {
|
||||
data.key = 'end';
|
||||
logger.info('End: status=%d score=%d time=%dms memory=%dkb', data.status, data.score, data.time, data.memory);
|
||||
t._callbackAwait = t._callbackAwait.then(() => JudgeHandler.end({ ...data, rid: t.rid, domainId: t.request.domainId }));
|
||||
getReporter(t: Context) {
|
||||
const reporter = new JudgeResultCallbackContext(app, t.request);
|
||||
return {
|
||||
next: (a) => reporter.next(a),
|
||||
end: (a) => reporter.end(a),
|
||||
};
|
||||
},
|
||||
getLang(lang: string, doThrow = true) {
|
||||
|
||||
@@ -106,8 +106,8 @@ export default class Hydro implements Session {
|
||||
this.ws.send(JSON.stringify({ ...data, rid, key }));
|
||||
}
|
||||
|
||||
getNext(t: JudgeTask) {
|
||||
return (data: Partial<JudgeResultBody>) => {
|
||||
getReporter(t: JudgeTask) {
|
||||
const next = (data: Partial<JudgeResultBody>) => {
|
||||
log.debug('Next: %o', data);
|
||||
const performanceMode = getConfig('performance') || t.meta.rejudge || t.meta.hackRejudge;
|
||||
if (performanceMode && data.case && !data.compilerText && !data.message) {
|
||||
@@ -119,14 +119,12 @@ export default class Hydro implements Session {
|
||||
this.send(t.request.rid, 'next', data);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
getEnd(t: JudgeTask) {
|
||||
return (data: Partial<JudgeResultBody>) => {
|
||||
const end = (data: Partial<JudgeResultBody>) => {
|
||||
log.info('End: %o', data);
|
||||
if (t.callbackCache) data.cases = t.callbackCache;
|
||||
this.send(t.request.rid, 'end', data);
|
||||
};
|
||||
return { next, end };
|
||||
}
|
||||
|
||||
async consume(queue: PQueue) {
|
||||
|
||||
@@ -79,18 +79,16 @@ export default class VJ4 implements Session {
|
||||
this.ws.send(JSON.stringify({ ...data, tag, key }));
|
||||
}
|
||||
|
||||
getNext(t: JudgeTask) {
|
||||
return (data: Partial<JudgeResultBody>) => {
|
||||
getReporter(t: JudgeTask) {
|
||||
const next = (data: Partial<JudgeResultBody>) => {
|
||||
log.debug('Next: %o', data);
|
||||
this.send((t.request as any).tag, 'next', data);
|
||||
};
|
||||
}
|
||||
|
||||
getEnd(t: JudgeTask) {
|
||||
return (data: Partial<JudgeResultBody>) => {
|
||||
const end = (data: Partial<JudgeResultBody>) => {
|
||||
log.info('End: %o', data);
|
||||
this.send((t.request as any).tag, 'end', data);
|
||||
};
|
||||
return { next, end };
|
||||
}
|
||||
|
||||
get(url: string) {
|
||||
|
||||
Reference in new issue
Block a user