mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-21 01:46:28 +08:00
judge: remove unused tmpdir
This commit is contained in:
1 parent
18d59edc82
commit
b292c6cfa3
9 files changed
+8
-42
No files matched your search
@@ -27,7 +27,6 @@ Syncing testdata, please wait...: 正在同步测试数据,请稍候...
|
|||||||
Temp directory: 临时目录
|
Temp directory: 临时目录
|
||||||
Testdata cache directory: 测试数据缓存目录
|
Testdata cache directory: 测试数据缓存目录
|
||||||
Testdata configuration incorrect.: 题目配置错误。
|
Testdata configuration incorrect.: 题目配置错误。
|
||||||
Tmpfs size: tmpfs 分区大小
|
|
||||||
Too many files.: 文件过多。
|
Too many files.: 文件过多。
|
||||||
Too many testcases. Cancelled.: 测试数据过多。评测取消。
|
Too many testcases. Cancelled.: 测试数据过多。评测取消。
|
||||||
Total time limit longer than {0}s. Cancelled.: 总时限超过{0}s。评测取消。
|
Total time limit longer than {0}s. Cancelled.: 总时限超过{0}s。评测取消。
|
||||||
|
|||||||
@@ -8,11 +8,6 @@ tmp_dir:
|
|||||||
name: tmp_dir
|
name: tmp_dir
|
||||||
desc: Temp directory
|
desc: Temp directory
|
||||||
default: $TEMP/hydro/judge
|
default: $TEMP/hydro/judge
|
||||||
tmpfs_size:
|
|
||||||
type: text
|
|
||||||
name: tmpfs_size
|
|
||||||
desc: Tmpfs size
|
|
||||||
default: 256m
|
|
||||||
stdio_size:
|
stdio_size:
|
||||||
type: text
|
type: text
|
||||||
name: stdio_size
|
name: stdio_size
|
||||||
|
|||||||
@@ -10,7 +10,6 @@ const argv = cac().parse();
|
|||||||
const JudgeSettings = Schema.object({
|
const JudgeSettings = Schema.object({
|
||||||
cache_dir: Schema.string().default(path.resolve(os.homedir(), '.cache', 'hydro', 'judge')),
|
cache_dir: Schema.string().default(path.resolve(os.homedir(), '.cache', 'hydro', 'judge')),
|
||||||
tmp_dir: Schema.string().default(path.resolve(os.tmpdir(), 'hydro', 'judge')),
|
tmp_dir: Schema.string().default(path.resolve(os.tmpdir(), 'hydro', 'judge')),
|
||||||
tmpfs_size: Schema.string().pattern(/^\d+[kmg]b?$/g).default('256m'),
|
|
||||||
stdio_size: Schema.string().pattern(/^\d+[kmg]b?$/g).default('32m'),
|
stdio_size: Schema.string().pattern(/^\d+[kmg]b?$/g).default('32m'),
|
||||||
memoryMax: Schema.string().pattern(/^\d+[kmg]b?$/g).default('512m'),
|
memoryMax: Schema.string().pattern(/^\d+[kmg]b?$/g).default('512m'),
|
||||||
strict_memory: Schema.boolean().default(false),
|
strict_memory: Schema.boolean().default(false),
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ let exit = false;
|
|||||||
const terminate = async () => {
|
const terminate = async () => {
|
||||||
log.info('正在保存数据');
|
log.info('正在保存数据');
|
||||||
try {
|
try {
|
||||||
await Promise.all(global.onDestroy.map((f: Function) => f()));
|
await Promise.all(global.hosts.map((f) => f.dispose?.()));
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
if (exit) process.exit(1);
|
if (exit) process.exit(1);
|
||||||
|
|||||||
@@ -173,7 +173,6 @@ export default class Hydro {
|
|||||||
Authorization: `Bearer ${this.config.cookie.split('sid=')[1].split(';')[0]}`,
|
Authorization: `Bearer ${this.config.cookie.split('sid=')[1].split(';')[0]}`,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
global.onDestroy.push(() => this.ws.close());
|
|
||||||
const content = this.config.minPriority !== undefined
|
const content = this.config.minPriority !== undefined
|
||||||
? `{"key":"prio","prio":${this.config.minPriority}}`
|
? `{"key":"prio","prio":${this.config.minPriority}}`
|
||||||
: '{"key":"ping"}';
|
: '{"key":"ping"}';
|
||||||
@@ -207,6 +206,10 @@ export default class Hydro {
|
|||||||
log.info(`[${this.config.host}] 已连接`);
|
log.info(`[${this.config.host}] 已连接`);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
dispose() {
|
||||||
|
this.ws?.close?.();
|
||||||
|
}
|
||||||
|
|
||||||
async setCookie(cookie: string) {
|
async setCookie(cookie: string) {
|
||||||
this.config.cookie = cookie;
|
this.config.cookie = cookie;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
/* eslint-disable no-sequences */
|
/* eslint-disable no-sequences */
|
||||||
import { basename } from 'path';
|
import { basename } from 'path';
|
||||||
|
import { unlinkSync } from 'fs';
|
||||||
import { STATUS } from '@hydrooj/utils/lib/status';
|
import { STATUS } from '@hydrooj/utils/lib/status';
|
||||||
import checkers from '../checkers';
|
import checkers from '../checkers';
|
||||||
import compile, { compileChecker, compileValidator } from '../compile';
|
import compile, { compileChecker, compileValidator } from '../compile';
|
||||||
@@ -25,6 +26,7 @@ export async function judge(ctx: Context) {
|
|||||||
compileValidator(session.getLang, config.validator, judgeExtraFiles).then(markCleanup),
|
compileValidator(session.getLang, config.validator, judgeExtraFiles).then(markCleanup),
|
||||||
ctx.session.fetchFile(ctx.files.hack),
|
ctx.session.fetchFile(ctx.files.hack),
|
||||||
]);
|
]);
|
||||||
|
ctx.clean.push(async () => unlinkSync(input));
|
||||||
ctx.next({ status: STATUS.STATUS_JUDGING, progress: 0 });
|
ctx.next({ status: STATUS.STATUS_JUDGING, progress: 0 });
|
||||||
const validateResult = await run(
|
const validateResult = await run(
|
||||||
validator.execute,
|
validator.execute,
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ declare module 'hydrooj' {
|
|||||||
interface SystemKeys {
|
interface SystemKeys {
|
||||||
'hydrojudge.cache_dir': string;
|
'hydrojudge.cache_dir': string;
|
||||||
'hydrojudge.tmp_dir': string;
|
'hydrojudge.tmp_dir': string;
|
||||||
'hydrojudge.tmpfs_size': string;
|
|
||||||
'hydrojudge.sandbox_host': string;
|
'hydrojudge.sandbox_host': string;
|
||||||
'hydrojudge.memoryMax': string;
|
'hydrojudge.memoryMax': string;
|
||||||
'hydrojudge.testcases_max': number;
|
'hydrojudge.testcases_max': number;
|
||||||
|
|||||||
@@ -12,8 +12,7 @@ import { NextFunction, ParsedConfig } from './interface';
|
|||||||
import judge from './judge';
|
import judge from './judge';
|
||||||
import { Logger } from './log';
|
import { Logger } from './log';
|
||||||
import { CopyInFile } from './sandbox';
|
import { CopyInFile } from './sandbox';
|
||||||
import * as tmpfs from './tmpfs';
|
import { compilerText, md5 } from './utils';
|
||||||
import { compilerText, Lock, md5 } from './utils';
|
|
||||||
|
|
||||||
interface Session {
|
interface Session {
|
||||||
getLang: (name: string) => LangConfig;
|
getLang: (name: string) => LangConfig;
|
||||||
@@ -32,7 +31,6 @@ export class JudgeTask {
|
|||||||
rid: string;
|
rid: string;
|
||||||
lang: string;
|
lang: string;
|
||||||
code: CopyInFile;
|
code: CopyInFile;
|
||||||
tmpdir: string;
|
|
||||||
input?: string;
|
input?: string;
|
||||||
clean: (() => Promise<any>)[];
|
clean: (() => Promise<any>)[];
|
||||||
data: FileInfo[];
|
data: FileInfo[];
|
||||||
@@ -73,11 +71,7 @@ export class JudgeTask {
|
|||||||
};
|
};
|
||||||
this.next = this.session.getNext(this);
|
this.next = this.session.getNext(this);
|
||||||
this.end = this.session.getEnd(this);
|
this.end = this.session.getEnd(this);
|
||||||
this.tmpdir = path.resolve(getConfig('tmp_dir'), this.rid);
|
|
||||||
this.clean = [];
|
this.clean = [];
|
||||||
await Lock.acquire(`${host}/${this.source}/${this.rid}`);
|
|
||||||
fs.ensureDirSync(this.tmpdir);
|
|
||||||
tmpfs.mount(this.tmpdir, getConfig('tmpfs_size'));
|
|
||||||
logger.info('Submission: %s/%s/%s', host, this.source, this.rid);
|
logger.info('Submission: %s/%s/%s', host, this.source, this.rid);
|
||||||
await this.doSubmission();
|
await this.doSubmission();
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
@@ -100,11 +94,8 @@ export class JudgeTask {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
Lock.release(`${host}/${this.source}/${this.rid}`);
|
|
||||||
// eslint-disable-next-line no-await-in-loop
|
// eslint-disable-next-line no-await-in-loop
|
||||||
for (const clean of this.clean) await clean()?.catch(() => null);
|
for (const clean of this.clean) await clean()?.catch(() => null);
|
||||||
tmpfs.umount(this.tmpdir);
|
|
||||||
fs.removeSync(this.tmpdir);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,22 +0,0 @@
|
|||||||
import assert from 'assert';
|
|
||||||
import child from 'child_process';
|
|
||||||
import os from 'os';
|
|
||||||
import fs from 'fs-extra';
|
|
||||||
import log from './log';
|
|
||||||
|
|
||||||
const linux = os.platform() === 'linux';
|
|
||||||
if (!linux) log.warn('Not running on linux. tmpfs disabled.');
|
|
||||||
|
|
||||||
const userInfo = os.userInfo();
|
|
||||||
const uid = userInfo.uid;
|
|
||||||
if (uid !== 0) log.warn('Not running by root. tmpfs disabled.');
|
|
||||||
|
|
||||||
export function mount(path: string, size = '32m') {
|
|
||||||
fs.ensureDirSync(path);
|
|
||||||
assert(size.match(/^\d+[kmg]b?$/gi));
|
|
||||||
if (linux && uid === 0) child.execSync(`mount tmpfs ${path} -t tmpfs -o size=${size}`);
|
|
||||||
}
|
|
||||||
|
|
||||||
export function umount(path: string) {
|
|
||||||
if (linux && uid === 0) child.execSync(`umount ${path}`);
|
|
||||||
}
|
|
||||||
Reference in new issue
Block a user