judge: allow prepare with startPromise

pull/328/head
undefined 3 years ago
parent 510ca21cf5
commit dd157a5e3b

@ -1,7 +1,7 @@
{
"name": "@hydrooj/hydrojudge",
"bin": "bin/hydrojudge.js",
"version": "2.14.9",
"version": "2.14.10",
"main": "package.json",
"author": "undefined <i@undefined.moe>",
"repository": "https://github.com/hydro-dev/Hydro.git",

@ -51,7 +51,7 @@ class JudgeTask {
this.getLang = session.getLang;
}
async handle() {
async handle(startPromise = Promise.resolve()) {
this.next = this.next.bind(this);
this.end = this.end.bind(this);
this.stat.handle = new Date();
@ -78,7 +78,7 @@ class JudgeTask {
tmpfs.mount(this.tmpdir, getConfig('tmpfs_size'));
log.info('Submission: %s/%s/%s', this.host, this.source, this.rid);
try {
await this.doSubmission();
await this.doSubmission(startPromise);
} catch (e) {
if (e instanceof CompileError) {
this.next({ compiler_text: compilerText(e.stdout, e.stderr) });
@ -106,7 +106,7 @@ class JudgeTask {
}
}
async doSubmission() {
async doSubmission(startPromise = Promise.resolve()) {
this.stat.cache_start = new Date();
this.folder = await this.session.cacheOpen(this.source, this.data, this.next);
this.stat.read_cases = new Date();
@ -122,7 +122,7 @@ class JudgeTask {
this.stat.judge = new Date();
const type = typeof this.input === 'string' ? 'run' : this.config.type || 'default';
if (!judge[type]) throw new FormatError('Unrecognized problemType: {0}', [type]);
await judge[type].judge(this);
await judge[type].judge(this, startPromise);
}
next(data, id?: number) {

@ -133,9 +133,9 @@ function judgeSubtask(subtask: SubTask, sid: string) {
};
}
export const judge = async (ctx: Context) => {
export const judge = async (ctx: Context, startPromise = Promise.resolve()) => {
if (!ctx.config.subtasks.length) throw new FormatError('Problem data not found.');
ctx.next({ status: STATUS.STATUS_COMPILING });
startPromise.then(() => ctx.next({ status: STATUS.STATUS_COMPILING }));
if (ctx.config.template) {
if (ctx.config.template[ctx.lang]) {
const tpl = ctx.config.template[ctx.lang];
@ -167,6 +167,7 @@ export const judge = async (ctx: Context) => {
})(),
]);
ctx.clean.push(ctx.execute.clean, ctx.checker.clean);
await startPromise;
ctx.next({ status: STATUS.STATUS_JUDGING, progress: 0 });
const tasks = [];
ctx.total_status = 0;

@ -6,4 +6,4 @@ import * as submit_answer from './submit_answer';
export = {
default: def, interactive, run, submit_answer, objective: submit_answer,
} as Record<string, { judge(ctx: Context): Promise<void> }>;
} as Record<string, { judge(ctx: Context, startPromise?: Promise<any>): Promise<void> }>;

@ -71,7 +71,7 @@ function judgeCase(c: Case) {
message,
},
progress: Math.floor((c.id * 100) / ctx.config.count),
});
}, c.id);
};
}
@ -95,8 +95,8 @@ function judgeSubtask(subtask: SubTask) {
};
}
export const judge = async (ctx: Context) => {
ctx.next({ status: STATUS.STATUS_COMPILING });
export const judge = async (ctx: Context, startPromise = Promise.resolve()) => {
startPromise.then(() => ctx.next({ status: STATUS.STATUS_COMPILING }));
[ctx.executeUser, ctx.executeInteractor] = await Promise.all([
(() => {
const copyIn = {};
@ -121,6 +121,7 @@ export const judge = async (ctx: Context) => {
})(),
]);
ctx.clean.push(ctx.executeUser.clean, ctx.executeInteractor.clean);
await startPromise;
ctx.next({ status: STATUS.STATUS_JUDGING, progress: 0 });
const tasks = [];
ctx.total_status = ctx.total_score = ctx.total_memory_usage_kb = ctx.total_time_usage_ms = 0;

Loading…
Cancel
Save