From d0592eac5b36bd12bfc3019265f6b58c51e5da6c Mon Sep 17 00:00:00 2001 From: undefined Date: Tue, 3 Aug 2021 12:27:14 +0800 Subject: [PATCH] =?UTF-8?q?judge:=20=E4=BC=98=E5=8C=96=E6=B5=8B=E8=AF=95?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=E5=90=8C=E6=AD=A5=E6=B5=81=E7=A8=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/hydrojudge/package.json | 2 +- packages/hydrojudge/src/hosts/hydro.ts | 13 +++++++++++-- packages/hydrojudge/src/judge/default.ts | 4 ++++ 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/packages/hydrojudge/package.json b/packages/hydrojudge/package.json index 90eff7cbc..bcd88410f 100644 --- a/packages/hydrojudge/package.json +++ b/packages/hydrojudge/package.json @@ -1,7 +1,7 @@ { "name": "@hydrooj/hydrojudge", "bin": "bin/hydrojudge.js", - "version": "2.9.3", + "version": "2.9.4", "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 224fd1bf9..62b190651 100644 --- a/packages/hydrojudge/src/hosts/hydro.ts +++ b/packages/hydrojudge/src/hosts/hydro.ts @@ -3,6 +3,7 @@ import path from 'path'; import axios from 'axios'; import fs from 'fs-extra'; import WebSocket from 'ws'; +import PQueue from 'p-queue'; import cac from 'cac'; import { noop } from 'lodash'; import { ObjectID } from 'mongodb'; @@ -212,13 +213,14 @@ export default class Hydro { } if (filenames.length) { log.info(`Getting problem data: ${this.config.host}/${domainId}/${pid}`); - if (next) next({ judge_text: '正在同步测试数据,请稍后' }); + if (next) next({ judge_text: '正在同步测试数据,请稍候' }); await this.ensureLogin(); const res = await this.axios.post(`/d/${domainId}/judge/files`, { pid, files: filenames, }); - for (const name in res.data.links) { + // eslint-disable-next-line no-inner-declarations + async function download(name: string) { if (name.includes('/')) await fs.ensureDir(path.join(filePath, name.split('/')[0])); const f = await this.axios.get(res.data.links[name], { responseType: 'stream' }); const w = fs.createWriteStream(path.join(filePath, name)); @@ -228,6 +230,13 @@ export default class Hydro { w.on('error', reject); }); } + const tasks = []; + const queue = new PQueue({ concurrency: 10 }); + for (const name in res.data.links) { + tasks.push(queue.add(() => download(name))); + } + queue.start(); + await Promise.all(tasks); fs.writeFileSync(path.join(filePath, 'etags'), JSON.stringify(version)); await this.processData(filePath).catch(noop); } diff --git a/packages/hydrojudge/src/judge/default.ts b/packages/hydrojudge/src/judge/default.ts index 66d498737..590103308 100644 --- a/packages/hydrojudge/src/judge/default.ts +++ b/packages/hydrojudge/src/judge/default.ts @@ -88,6 +88,10 @@ function judgeCase(c, sid: string) { if (code < 32) message = signals[code]; else message = { message: 'Your program returned {0}.', params: [code] }; } + await Promise.all([ + fs.remove(stdout), + fs.remove(stderr), + ]).catch(() => { /* Ignore file doesn't exist */ }); ctxSubtask.score = Score[ctxSubtask.subtask.type](ctxSubtask.score, score); ctxSubtask.status = Math.max(ctxSubtask.status, status); ctx.total_time_usage_ms += time_usage_ms;