core: use common plugin-api interface

This commit is contained in:
undefined committed 2022-09-30 19:02:40 +08:00
1 parent c61c875bee
commit 70a96aecac
54 files changed
+387 -566

No files matched your search

+11 -13
View File
@@ -3,12 +3,10 @@
import path from 'path';
import fs from 'fs-extra';
import type { JudgeResultBody } from 'hydrooj';
import {
Logger, SettingModel, StorageModel, SystemModel, TaskModel,
} from 'hydrooj';
import { end, next } from 'hydrooj/src/handler/judge';
import { Logger } from 'hydrooj/src/logger';
import * as setting from 'hydrooj/src/model/setting';
import storage from 'hydrooj/src/model/storage';
import * as system from 'hydrooj/src/model/system';
import task from 'hydrooj/src/model/task';
import { processTestdata } from '../cases';
import { getConfig } from '../config';
import { FormatError, SystemError } from '../error';
@@ -18,11 +16,11 @@ import { JudgeTask } from '../task';
const logger = new Logger('judge');
const session = {
config: { detail: system.get('hydrojudge.detail') },
config: { detail: SystemModel.get('hydrojudge.detail') },
async fetchFile(name: string) {
name = name.split('#')[0];
const target = path.join(getConfig('tmp_dir'), name.replace(/\//g, '_'));
await storage.get(`submission/${name}`, target);
await StorageModel.get(`submission/${name}`, target);
return target;
},
getNext(t: Context) {
@@ -42,8 +40,8 @@ const session = {
};
},
getLang(lang: string, doThrow = true) {
if (setting.langs[lang]) return setting.langs[lang];
if (lang === 'cpp' && setting.langs['cc']) return setting.langs['cc'];
if (SettingModel.langs[lang]) return SettingModel.langs[lang];
if (lang === 'cpp' && SettingModel.langs['cc']) return SettingModel.langs['cc'];
if (doThrow) throw new SystemError('Unsupported language {0}.', [lang]);
return null;
},
@@ -61,7 +59,7 @@ const session = {
filenames.add(file.name);
version[file.name] = file.etag + file.lastModified;
if (etags[file.name] !== file.etag + file.lastModified) {
await storage.get(`problem/${source}/testdata/${file.name}`, path.join(filePath, file.name));
await StorageModel.get(`problem/${source}/testdata/${file.name}`, path.join(filePath, file.name));
}
}
for (const name in etags) {
@@ -77,8 +75,8 @@ const session = {
};
export async function postInit() {
if (system.get('hydrojudge.disable')) return;
if (SystemModel.get('hydrojudge.disable')) return;
const handle = (t) => (new JudgeTask(session, t)).handle().catch(logger.error);
task.consume({ type: 'judge' }, handle);
task.consume({ type: 'judge', priority: { $gt: -50 } }, handle);
TaskModel.consume({ type: 'judge' }, handle);
TaskModel.consume({ type: 'judge', priority: { $gt: -50 } }, handle);
}
+6 -4
View File
@@ -1,6 +1,6 @@
import * as bus from 'hydrooj/src/service/bus';
import { Context } from 'hydrooj';
declare module 'hydrooj/src/interface' {
declare module 'hydrooj' {
interface SystemKeys {
'hydrojudge.cache_dir': string;
'hydrojudge.tmp_dir': string;
@@ -15,6 +15,8 @@ declare module 'hydrooj/src/interface' {
}
}
if (process.env.NODE_APP_INSTANCE === '0') {
bus.once('app/started', () => require('./hosts/builtin').postInit());
export function apply(ctx: Context) {
if (process.env.NODE_APP_INSTANCE === '0') {
ctx.once('app/started', () => require('./hosts/builtin').postInit());
}
}