bug fixes

This commit is contained in:
undefined committed 2025-03-28 09:41:45 +08:00
1 parent 56311e1209
commit ec23e81f8e
18 files changed
+90 -72

No files matched your search

+5 -3
View File
@@ -117,15 +117,17 @@ export async function load(ctx: Context) {
resolve(c);
});
});
await ctx.loader.reloadPlugin(require.resolve('../service/storage'), 'file');
await Promise.all([
ctx.loader.reloadPlugin(require.resolve('../service/storage'), 'file'),
ctx.loader.reloadPlugin(require.resolve('../service/worker'), 'worker'),
ctx.loader.reloadPlugin(require.resolve('../service/server'), 'server'),
]);
require('../lib/index');
await Promise.all([
service(pending, fail, ctx),
]);
ctx.plugin(require('../service/worker'));
await builtinModel(ctx);
await model(pending, fail, ctx);
ctx.plugin(require('../service/server'));
ctx = await new Promise((resolve) => {
ctx.inject(['server', 'setting', 'worker'], (c) => {
resolve(c);
+4 -1
View File
@@ -110,9 +110,12 @@ export class Loader extends Service {
if (!plugin) return;
const config = await this.resolveConfig(plugin, configScope);
let fork = this.state[key];
const displayPath = key.includes('node_modules')
? key.split('node_modules').pop()
: path.relative(process.cwd(), key);
logger.info(
`%s plugin %c${configScope ? ' with scope %c' : ''}`,
fork ? 'reload' : 'apply', key.split('node_modules').pop(), configScope,
fork ? 'reload' : 'apply', displayPath, configScope,
);
if (fork) {
fork.update(config);
+3 -8
View File
@@ -5,7 +5,7 @@ import path from 'path';
import AdmZip from 'adm-zip';
import fs from 'fs-extra';
import yaml from 'js-yaml';
import { pick } from 'lodash';
import { keyBy, pick } from 'lodash';
import { Filter, ObjectId } from 'mongodb';
import type { Readable } from 'stream';
import { ProblemConfigFile, ProblemType } from '@hydrooj/common';
@@ -409,12 +409,7 @@ export class ProblemModel {
const psdocs = await ProblemModel.getMultiStatus(
domainId, { uid, docId: { $in: Array.from(new Set(pids)) } },
).toArray();
const r: Record<string, ProblemStatusDoc> = {};
for (const psdoc of psdocs) {
r[psdoc.docId] = psdoc;
r[`${psdoc.domainId}#${psdoc.docId}`] = psdoc;
}
return r;
return keyBy(psdocs, 'docId');
}
static async updateStatus(
@@ -468,7 +463,7 @@ export class ProblemModel {
throw new ValidationError('zip', null, e.message);
}
await new Promise((resolve, reject) => {
zip.extractAllToAsync(tmpdir, true, (err) => {
zip.extractAllToAsync(tmpdir, true, false, (err) => {
if (err) reject(err);
resolve(null);
});
+1 -1
View File
@@ -252,7 +252,7 @@ export default class RecordModel {
RecordModel.collStat.deleteMany({ _id: { $in: rids } }),
task.deleteMany({ rid: { $in: rids } }),
]);
await RecordModel.collHistory.insertMany(rdocs.map((rdoc) => ({
await RecordModel.collHistory.insertMany(rdocs.filter((rdoc) => rdoc.judgeAt).map((rdoc) => ({
...pick(rdoc, [
'compilerTexts', 'judgeTexts', 'testCases', 'subtasks',
'score', 'time', 'memory', 'status', 'judgeAt', 'judger',
+15 -18
View File
@@ -178,7 +178,7 @@ async function cleanFiles() {
}
}
export function apply(ctx: Context) {
export async function apply(ctx: Context) {
ctx.inject(['worker'], (c) => {
c.worker.addHandler('storage.prune', cleanFiles);
});
@@ -190,24 +190,21 @@ export function apply(ctx: Context) {
]);
await StorageModel.del(problemFiles.concat(contestFiles).concat(trainingFiles).map((i) => i.path));
});
if (process.env.NODE_APP_INSTANCE !== '0') return;
ctx.on('ready', async () => {
await db.ensureIndexes(
StorageModel.coll,
{ key: { path: 1 }, name: 'path' },
{ key: { path: 1, autoDelete: 1 }, sparse: true, name: 'autoDelete' },
{ key: { link: 1 }, sparse: true, name: 'link' },
);
if (!await ScheduleModel.count({ type: 'schedule', subType: 'storage.prune' })) {
await ScheduleModel.add({
type: 'schedule',
subType: 'storage.prune',
executeAfter: moment().startOf('hour').toDate(),
interval: [1, 'hour'],
});
}
});
await db.ensureIndexes(
StorageModel.coll,
{ key: { path: 1 }, name: 'path' },
{ key: { path: 1, autoDelete: 1 }, sparse: true, name: 'autoDelete' },
{ key: { link: 1 }, sparse: true, name: 'link' },
);
if (!await ScheduleModel.count({ type: 'schedule', subType: 'storage.prune' })) {
await ScheduleModel.add({
type: 'schedule',
subType: 'storage.prune',
executeAfter: moment().startOf('hour').toDate(),
interval: [1, 'hour'],
});
}
}
global.Hydro.model.storage = StorageModel;
+1 -1
View File
@@ -62,7 +62,7 @@ export class MongoService extends Service {
yield () => { this.client.close(); };
this.db = this.client.db(url.database || 'hydro');
await bus.parallel('database/connect', this.db);
this.ctx.setInterval(() => this.fixExpireAfter(), Time.hour);
yield this.ctx.setInterval(() => this.fixExpireAfter(), Time.hour);
}
public collection<K extends keyof Collections>(c: K) {
+9 -12
View File
@@ -98,17 +98,14 @@ export async function updateJudge(args) {
);
}
export function apply(ctx: Context) {
export async function apply(ctx: Context) {
if (process.env.NODE_APP_INSTANCE !== '0') return;
ctx.on('app/started', async () => {
sysinfo.get().then((info) => {
coll.updateOne(
{ mid: info.mid, type: 'server' },
{ $set: { ...info, updateAt: new Date(), type: 'server' } },
{ upsert: true },
);
feedback();
setInterval(update, 1800 * 1000);
});
});
const info = await sysinfo.get();
coll.updateOne(
{ mid: info.mid, type: 'server' },
{ $set: { ...info, updateAt: new Date(), type: 'server' } },
{ upsert: true },
);
feedback();
return ctx.setInterval(update, 1800 * 1000); // eslint-disable-line
}
+7 -5
View File
@@ -18,7 +18,14 @@ export default class WorkerService extends Service {
constructor(ctx: Context) {
super(ctx, 'worker');
}
async *[Context.init]() {
this.consume();
yield () => {
this.consuming = false;
return this.promise;
};
}
async getFirst() {
@@ -79,9 +86,4 @@ export default class WorkerService extends Service {
};
});
}
public async stop() {
this.consuming = false;
await this.promise;
}
}