mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-21 01:46:28 +08:00
judge: support generate testdata (#695)
Co-authored-by: panda <panda_dtdyy@outlook.com>
This commit is contained in:
1 parent
b83b2e792e
commit
55b4e1aaf0
27 files changed
+454
-68
No files matched your search
@@ -6,7 +6,7 @@ import {
|
||||
JudgeResultBody, ObjectId, RecordModel, SettingModel,
|
||||
StorageModel, SystemModel, TaskModel,
|
||||
} from 'hydrooj';
|
||||
import { end, next } from 'hydrooj/src/handler/judge';
|
||||
import { end, next, processJudgeFileCallback } from 'hydrooj/src/handler/judge';
|
||||
import { getConfig } from '../config';
|
||||
import { FormatError, SystemError } from '../error';
|
||||
import { Context } from '../judge/interface';
|
||||
@@ -46,6 +46,9 @@ const session = {
|
||||
if (doThrow) throw new SystemError('Unsupported language {0}.', [lang]);
|
||||
return null;
|
||||
},
|
||||
async postFile(target: string, filename: string, filepath: string) {
|
||||
return await processJudgeFileCallback(new ObjectId(target), filename, filepath);
|
||||
},
|
||||
async cacheOpen(source: string, files: any[]) {
|
||||
const filePath = path.join(getConfig('cache_dir'), source);
|
||||
await fs.ensureDir(filePath);
|
||||
@@ -84,9 +87,10 @@ export async function postInit(ctx) {
|
||||
logger.debug('Record not found: %o', t);
|
||||
return;
|
||||
}
|
||||
await (new JudgeTask(session, Object.assign(rdoc, t))).handle().catch(logger.error);
|
||||
await (new JudgeTask(session, JSON.parse(JSON.stringify(Object.assign(rdoc, t))))).handle().catch(logger.error);
|
||||
};
|
||||
const parallelism = Math.max(getConfig('parallelism'), 2);
|
||||
for (let i = 1; i < parallelism; i++) TaskModel.consume({ type: 'judge' }, handle);
|
||||
TaskModel.consume({ type: 'judge', priority: { $gt: -50 } }, handle);
|
||||
TaskModel.consume({ type: 'generate' }, handle);
|
||||
}
|
||||
@@ -10,6 +10,7 @@ import * as sysinfo from '@hydrooj/utils/lib/sysinfo';
|
||||
import type { JudgeResultBody } from 'hydrooj';
|
||||
import { getConfig } from '../config';
|
||||
import { FormatError, SystemError } from '../error';
|
||||
import { Session } from '../interface';
|
||||
import log from '../log';
|
||||
import { JudgeTask } from '../task';
|
||||
import { Lock } from '../utils';
|
||||
@@ -18,7 +19,7 @@ function removeNixPath(text: string) {
|
||||
return text.replace(/\/nix\/store\/[a-z0-9]{32}-/g, '/nix/');
|
||||
}
|
||||
|
||||
export default class Hydro {
|
||||
export default class Hydro implements Session {
|
||||
ws: WebSocket;
|
||||
language: Record<string, LangConfig>;
|
||||
|
||||
@@ -134,6 +135,10 @@ export default class Hydro {
|
||||
return target;
|
||||
}
|
||||
|
||||
async postFile(target: string, file: string) {
|
||||
await this.post('judge/upload', { target }).attach('file', fs.createReadStream(file));
|
||||
}
|
||||
|
||||
getLang(name: string, doThrow = true) {
|
||||
if (this.language[name]) return this.language[name];
|
||||
if (name === 'cpp' && this.language.cc) return this.language.cc;
|
||||
|
||||
Reference in new issue
Block a user