From dd157a5e3b102799ad4c4241a0bbbd066f99e7b9 Mon Sep 17 00:00:00 2001 From: undefined Date: Fri, 25 Mar 2022 09:14:34 +0800 Subject: [PATCH] judge: allow prepare with startPromise --- packages/hydrojudge/package.json | 2 +- packages/hydrojudge/src/hosts/hydro.ts | 8 ++++---- packages/hydrojudge/src/judge/default.ts | 5 +++-- packages/hydrojudge/src/judge/index.ts | 2 +- packages/hydrojudge/src/judge/interactive.ts | 7 ++++--- 5 files changed, 13 insertions(+), 11 deletions(-) diff --git a/packages/hydrojudge/package.json b/packages/hydrojudge/package.json index 7f518f8a7..fcfe5d444 100644 --- a/packages/hydrojudge/package.json +++ b/packages/hydrojudge/package.json @@ -1,7 +1,7 @@ { "name": "@hydrooj/hydrojudge", "bin": "bin/hydrojudge.js", - "version": "2.14.9", + "version": "2.14.10", "main": "package.json", "author": "undefined ", "repository": "https://github.com/hydro-dev/Hydro.git", diff --git a/packages/hydrojudge/src/hosts/hydro.ts b/packages/hydrojudge/src/hosts/hydro.ts index fc9ef47c9..e2534c333 100644 --- a/packages/hydrojudge/src/hosts/hydro.ts +++ b/packages/hydrojudge/src/hosts/hydro.ts @@ -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) { diff --git a/packages/hydrojudge/src/judge/default.ts b/packages/hydrojudge/src/judge/default.ts index 21ca1ebfa..c102ea5a7 100644 --- a/packages/hydrojudge/src/judge/default.ts +++ b/packages/hydrojudge/src/judge/default.ts @@ -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; diff --git a/packages/hydrojudge/src/judge/index.ts b/packages/hydrojudge/src/judge/index.ts index 53ef04a18..ab95671f7 100644 --- a/packages/hydrojudge/src/judge/index.ts +++ b/packages/hydrojudge/src/judge/index.ts @@ -6,4 +6,4 @@ import * as submit_answer from './submit_answer'; export = { default: def, interactive, run, submit_answer, objective: submit_answer, -} as Record }>; +} as Record): Promise }>; diff --git a/packages/hydrojudge/src/judge/interactive.ts b/packages/hydrojudge/src/judge/interactive.ts index fbbaa3858..ac5391fb9 100644 --- a/packages/hydrojudge/src/judge/interactive.ts +++ b/packages/hydrojudge/src/judge/interactive.ts @@ -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;