config: remove all setting.yaml

This commit is contained in:
undefined committed 2025-03-24 19:42:15 +08:00
1 parent e1f4f699b8
commit 9bdf241142
16 files changed
+373 -474

No files matched your search

+25 -16
View File
@@ -6,24 +6,31 @@ import { fs, yaml } from '@hydrooj/utils';
const argv = cac().parse();
const JudgeSettings = Schema.object({
cache_dir: Schema.string().default(path.resolve(os.homedir(), '.cache', 'hydro', 'judge')),
const defaultEnv = `\
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
HOME=/w
# modify to your python version installed
PYTHONPATH=/lib/python3.12/site-packages
`;
export const JudgeSettings = Schema.object({
cache_dir: Schema.string().default(path.resolve(os.homedir(), '.cache', 'hydro', 'judge')).description('Testdata cache directory'),
tmp_dir: Schema.string().default(path.resolve(os.tmpdir(), 'hydro', 'judge')),
stdio_size: Schema.string().pattern(/^\d+[kmg]b?$/g).default('32m'),
memoryMax: Schema.string().pattern(/^\d+[kmg]b?$/g).default('512m'),
strict_memory: Schema.boolean().default(false),
sandbox_host: Schema.string().role('link').default('http://localhost:5050'),
testcases_max: Schema.number().default(100),
total_time_limit: Schema.number().default(60),
processLimit: Schema.number().default(32),
parallelism: Schema.number().default(2),
strict_memory: Schema.boolean().default(false).description('Use address space memory limit'),
sandbox_host: Schema.string().role('url').default('http://localhost:5050'),
testcases_max: Schema.number().default(100).min(1).step(1),
total_time_limit: Schema.number().default(60).min(1),
processLimit: Schema.number().default(32).min(1).step(1),
parallelism: Schema.number().default(2).min(1).step(1),
concurrency: Schema.number(),
singleTaskParallelism: Schema.number().default(2),
rerun: Schema.number().description('Re-Run testcase if time-limit-exceeded (max per submission)').default(0),
singleTaskParallelism: Schema.number().default(2).min(1).step(1),
rerun: Schema.number().description('Re-Run testcase if time-limit-exceeded (max per submission)').default(0).min(0).step(1),
rate: Schema.number().default(1),
env: Schema.string().default('PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin\nHOME=/w'),
env: Schema.string().default(defaultEnv),
host: Schema.any(),
secret: Schema.string().description('Judge Token Secret').default(String.random(32)),
secret: Schema.string().description('Judge Token Secret').default('Hydro-Judge-Secret'),
disable: Schema.boolean().description('Disable builtin judge').default(false),
detail: Schema.boolean().description('Show diff detail').default(true),
performance: Schema.boolean().description('Performance mode').default(false),
@@ -32,7 +39,7 @@ const JudgeSettings = Schema.object({
const oldPath = path.resolve(os.homedir(), '.config', 'hydro', 'judge.yaml');
const newPath = path.resolve(os.homedir(), '.hydro', 'judge.yaml');
const config = global.Hydro
let config = global.Hydro
? JudgeSettings({})
: (() => {
const base: any = {};
@@ -54,6 +61,8 @@ const config = global.Hydro
return JudgeSettings(cfg);
})();
export const getConfig: <K extends keyof typeof config>(key: K) => typeof config[K] = global.Hydro
? (key) => global.Hydro.model.system.get(`hydrojudge.${key}`) ?? config[key]
: (key) => config[key];
export function overrideConfig(update: ReturnType<typeof JudgeSettings>) {
config = JudgeSettings(update);
}
export const getConfig: <K extends keyof typeof config>(key: K) => typeof config[K] = (key) => config[key];
+9 -7
View File
@@ -4,7 +4,7 @@ import path from 'path';
import { fs } from '@hydrooj/utils';
import * as sysinfo from '@hydrooj/utils/lib/sysinfo';
import {
db, JudgeHandler, JudgeResultBody, ObjectId, RecordModel,
Context as HydroContext, db, JudgeHandler, JudgeResultBody, ObjectId, RecordModel,
SettingModel, StorageModel, SystemModel, TaskModel,
} from 'hydrooj';
import { langs } from 'hydrooj/src/model/setting';
@@ -59,10 +59,11 @@ const session: Session = {
},
};
export async function postInit(ctx) {
if (SystemModel.get('hydrojudge.disable')) return;
export async function* apply(ctx: HydroContext) {
ctx.inject(['check'], (c) => {
c.check.addChecker('Judge', (_ctx, log, warn, error) => versionCheck(warn, error));
c.check.addChecker('Judge', async (_ctx, log, warn, error) => {
await versionCheck(warn, error);
});
});
await fs.ensureDir(getConfig('tmp_dir'));
const info = await sysinfo.get();
@@ -76,6 +77,7 @@ export async function postInit(ctx) {
};
const parallelism = Math.max(getConfig('parallelism'), 2);
const taskConsumer = TaskModel.consume({ type: 'judge' }, handle, true, parallelism);
yield () => taskConsumer.destroy();
async function collectInfo() {
const coll = db.collection('status');
const compilers = await compilerVersions(langs);
@@ -91,11 +93,11 @@ export async function postInit(ctx) {
{ upsert: true },
);
}
ctx.on('system/setting', () => {
yield ctx.on('system/setting', () => {
taskConsumer.setConcurrency(Math.max(getConfig('parallelism'), 2));
collectInfo();
});
collectInfo();
TaskModel.consume({ type: 'judge', priority: { $gt: -50 } }, handle);
TaskModel.consume({ type: 'generate' }, handle);
const generateConsumer = TaskModel.consume({ type: 'generate' }, handle);
yield () => generateConsumer.destroy();
}
+6 -15
View File
@@ -1,20 +1,11 @@
import { Context } from 'hydrooj';
import { JudgeSettings, overrideConfig } from './config';
declare module 'hydrooj' {
interface SystemKeys {
'hydrojudge.cache_dir': string;
'hydrojudge.tmp_dir': string;
'hydrojudge.sandbox_host': string;
'hydrojudge.memoryMax': string;
'hydrojudge.testcases_max': number;
'hydrojudge.total_time_limit': number;
'hydrojudge.parallelism': number;
'hydrojudge.disable': boolean;
'hydrojudge.detail': boolean;
}
}
export const Config = JudgeSettings;
export function apply(ctx: Context) {
export function apply(ctx: Context, config: ReturnType<typeof Config>) {
if (process.env.NODE_APP_INSTANCE !== '0') return;
ctx.once('app/started', () => require('./hosts/builtin').postInit(ctx));
overrideConfig(config);
// eslint-disable-next-line consistent-return
if (!config.disable) return require('./hosts/builtin').apply(ctx);
}