mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
judge: allow prepare with startPromise
This commit is contained in:
1 parent
510ca21cf5
commit
dd157a5e3b
5 files changed
+13
-11
No files matched your search
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "@hydrooj/hydrojudge",
|
"name": "@hydrooj/hydrojudge",
|
||||||
"bin": "bin/hydrojudge.js",
|
"bin": "bin/hydrojudge.js",
|
||||||
"version": "2.14.9",
|
"version": "2.14.10",
|
||||||
"main": "package.json",
|
"main": "package.json",
|
||||||
"author": "undefined <i@undefined.moe>",
|
"author": "undefined <i@undefined.moe>",
|
||||||
"repository": "https://github.com/hydro-dev/Hydro.git",
|
"repository": "https://github.com/hydro-dev/Hydro.git",
|
||||||
|
|||||||
@@ -51,7 +51,7 @@ class JudgeTask {
|
|||||||
this.getLang = session.getLang;
|
this.getLang = session.getLang;
|
||||||
}
|
}
|
||||||
|
|
||||||
async handle() {
|
async handle(startPromise = Promise.resolve()) {
|
||||||
this.next = this.next.bind(this);
|
this.next = this.next.bind(this);
|
||||||
this.end = this.end.bind(this);
|
this.end = this.end.bind(this);
|
||||||
this.stat.handle = new Date();
|
this.stat.handle = new Date();
|
||||||
@@ -78,7 +78,7 @@ class JudgeTask {
|
|||||||
tmpfs.mount(this.tmpdir, getConfig('tmpfs_size'));
|
tmpfs.mount(this.tmpdir, getConfig('tmpfs_size'));
|
||||||
log.info('Submission: %s/%s/%s', this.host, this.source, this.rid);
|
log.info('Submission: %s/%s/%s', this.host, this.source, this.rid);
|
||||||
try {
|
try {
|
||||||
await this.doSubmission();
|
await this.doSubmission(startPromise);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
if (e instanceof CompileError) {
|
if (e instanceof CompileError) {
|
||||||
this.next({ compiler_text: compilerText(e.stdout, e.stderr) });
|
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.stat.cache_start = new Date();
|
||||||
this.folder = await this.session.cacheOpen(this.source, this.data, this.next);
|
this.folder = await this.session.cacheOpen(this.source, this.data, this.next);
|
||||||
this.stat.read_cases = new Date();
|
this.stat.read_cases = new Date();
|
||||||
@@ -122,7 +122,7 @@ class JudgeTask {
|
|||||||
this.stat.judge = new Date();
|
this.stat.judge = new Date();
|
||||||
const type = typeof this.input === 'string' ? 'run' : this.config.type || 'default';
|
const type = typeof this.input === 'string' ? 'run' : this.config.type || 'default';
|
||||||
if (!judge[type]) throw new FormatError('Unrecognized problemType: {0}', [type]);
|
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) {
|
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.');
|
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) {
|
||||||
if (ctx.config.template[ctx.lang]) {
|
if (ctx.config.template[ctx.lang]) {
|
||||||
const tpl = 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);
|
ctx.clean.push(ctx.execute.clean, ctx.checker.clean);
|
||||||
|
await startPromise;
|
||||||
ctx.next({ status: STATUS.STATUS_JUDGING, progress: 0 });
|
ctx.next({ status: STATUS.STATUS_JUDGING, progress: 0 });
|
||||||
const tasks = [];
|
const tasks = [];
|
||||||
ctx.total_status = 0;
|
ctx.total_status = 0;
|
||||||
|
|||||||
@@ -6,4 +6,4 @@ import * as submit_answer from './submit_answer';
|
|||||||
|
|
||||||
export = {
|
export = {
|
||||||
default: def, interactive, run, submit_answer, objective: submit_answer,
|
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,
|
message,
|
||||||
},
|
},
|
||||||
progress: Math.floor((c.id * 100) / ctx.config.count),
|
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) => {
|
export const judge = async (ctx: Context, startPromise = Promise.resolve()) => {
|
||||||
ctx.next({ status: STATUS.STATUS_COMPILING });
|
startPromise.then(() => ctx.next({ status: STATUS.STATUS_COMPILING }));
|
||||||
[ctx.executeUser, ctx.executeInteractor] = await Promise.all([
|
[ctx.executeUser, ctx.executeInteractor] = await Promise.all([
|
||||||
(() => {
|
(() => {
|
||||||
const copyIn = {};
|
const copyIn = {};
|
||||||
@@ -121,6 +121,7 @@ export const judge = async (ctx: Context) => {
|
|||||||
})(),
|
})(),
|
||||||
]);
|
]);
|
||||||
ctx.clean.push(ctx.executeUser.clean, ctx.executeInteractor.clean);
|
ctx.clean.push(ctx.executeUser.clean, ctx.executeInteractor.clean);
|
||||||
|
await startPromise;
|
||||||
ctx.next({ status: STATUS.STATUS_JUDGING, progress: 0 });
|
ctx.next({ status: STATUS.STATUS_JUDGING, progress: 0 });
|
||||||
const tasks = [];
|
const tasks = [];
|
||||||
ctx.total_status = ctx.total_score = ctx.total_memory_usage_kb = ctx.total_time_usage_ms = 0;
|
ctx.total_status = ctx.total_score = ctx.total_memory_usage_kb = ctx.total_time_usage_ms = 0;
|
||||||
|
|||||||
Reference in new issue
Block a user