mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
judge: builtin: ensure callback order
This commit is contained in:
2 files changed
+10
-9
No files matched your search
@@ -3,10 +3,9 @@
|
|||||||
import path from 'path';
|
import path from 'path';
|
||||||
import { fs } from '@hydrooj/utils';
|
import { fs } from '@hydrooj/utils';
|
||||||
import {
|
import {
|
||||||
JudgeResultBody, ObjectId, RecordModel, SettingModel,
|
JudgeHandler, JudgeResultBody, ObjectId, RecordModel, SettingModel,
|
||||||
StorageModel, SystemModel, TaskModel,
|
StorageModel, SystemModel, TaskModel,
|
||||||
} from 'hydrooj';
|
} from 'hydrooj';
|
||||||
import { end, next, processJudgeFileCallback } from 'hydrooj/src/handler/judge';
|
|
||||||
import { getConfig } from '../config';
|
import { getConfig } from '../config';
|
||||||
import { FormatError, SystemError } from '../error';
|
import { FormatError, SystemError } from '../error';
|
||||||
import { Context } from '../judge/interface';
|
import { Context } from '../judge/interface';
|
||||||
@@ -23,21 +22,21 @@ const session = {
|
|||||||
return target;
|
return target;
|
||||||
},
|
},
|
||||||
getNext(t: Context) {
|
getNext(t: Context) {
|
||||||
return async (data: Partial<JudgeResultBody>) => {
|
t._callbackAwait ||= Promise.resolve();
|
||||||
|
return (data: Partial<JudgeResultBody>) => {
|
||||||
logger.debug('Next: %o', data);
|
logger.debug('Next: %o', data);
|
||||||
data.rid = new ObjectId(t.rid);
|
data.rid = new ObjectId(t.rid);
|
||||||
const rdoc = await RecordModel.get(data.rid);
|
|
||||||
if (data.case) data.case.message ||= '';
|
if (data.case) data.case.message ||= '';
|
||||||
next({ ...data, domainId: rdoc.domainId });
|
t._callbackAwait = t._callbackAwait.then(() => JudgeHandler.next({ ...data, domainId: t.request.domainId }));
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
getEnd(t: Context) {
|
getEnd(t: Context) {
|
||||||
return async (data: Partial<JudgeResultBody>) => {
|
t._callbackAwait ||= Promise.resolve();
|
||||||
|
return (data: Partial<JudgeResultBody>) => {
|
||||||
data.key = 'end';
|
data.key = 'end';
|
||||||
data.rid = new ObjectId(t.rid);
|
data.rid = new ObjectId(t.rid);
|
||||||
const rdoc = await RecordModel.get(data.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, domainId: rdoc.domainId });
|
t._callbackAwait = t._callbackAwait.then(() => JudgeHandler.end({ ...data, domainId: t.request.domainId }));
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
getLang(lang: string, doThrow = true) {
|
getLang(lang: string, doThrow = true) {
|
||||||
@@ -47,7 +46,7 @@ const session = {
|
|||||||
return null;
|
return null;
|
||||||
},
|
},
|
||||||
async postFile(target: string, filename: string, filepath: string) {
|
async postFile(target: string, filename: string, filepath: string) {
|
||||||
return await processJudgeFileCallback(new ObjectId(target), filename, filepath);
|
return await JudgeHandler.processJudgeFileCallback(new ObjectId(target), filename, filepath);
|
||||||
},
|
},
|
||||||
async cacheOpen(source: string, files: any[]) {
|
async cacheOpen(source: string, files: any[]) {
|
||||||
const filePath = path.join(getConfig('cache_dir'), source);
|
const filePath = path.join(getConfig('cache_dir'), source);
|
||||||
|
|||||||
@@ -21,6 +21,8 @@ export interface RuntimeContext {
|
|||||||
checker?: Execute;
|
checker?: Execute;
|
||||||
executeInteractor?: Execute;
|
executeInteractor?: Execute;
|
||||||
executeUser?: Execute;
|
executeUser?: Execute;
|
||||||
|
|
||||||
|
_callbackAwait?: Promise<any>;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ContextSubTask {
|
export interface ContextSubTask {
|
||||||
|
|||||||
Reference in new issue
Block a user