core: judge: bug fix

This commit is contained in:
undefined committed 2024-01-28 08:29:37 +08:00
1 parent 571522aefa
commit 314bba6a0e
9 files changed
+20 -23

No files matched your search

+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "hydrooj",
"version": "4.10.5",
"version": "4.10.6",
"bin": "bin/hydrooj.js",
"main": "src/plugin-api",
"module": "src/plugin-api",
+3 -3
View File
@@ -72,7 +72,7 @@ function processPayload(body: Partial<JudgeResultBody>) {
}
export async function next(body: Partial<JudgeResultBody>) {
body.rid = new ObjectId(body.rid);
body.rid = new ObjectId(body.rid); // TODO remove this
const {
$set, $push, $unset, $inc,
} = processPayload(body);
@@ -141,7 +141,7 @@ export async function postJudge(rdoc: RecordDoc) {
}
export async function end(body: Partial<JudgeResultBody>) {
body.rid = new ObjectId(body.rid);
body.rid = new ObjectId(body.rid); // TODO remove this
const { $set, $push } = processPayload(body);
const $unset: any = { progress: '' };
$set.judgeAt = new Date();
@@ -269,7 +269,7 @@ export class JudgeConnectionHandler extends ConnectionHandler {
logger[method]('%o', omit(msg, keys));
}
if (['next', 'end'].includes(msg.key)) {
const t = this.tasks[msg.key];
const t = this.tasks[msg.rid];
if (!t) return;
msg.domainId = t.domainId;
if (msg.key === 'next') t.queue.add(() => next(msg));
+4 -4
View File
@@ -1,6 +1,6 @@
import { hostname } from 'os';
import cac from 'cac';
import { Filter, ObjectId } from 'mongodb';
import { BSON, Filter, ObjectId } from 'mongodb';
import { nanoid } from 'nanoid';
import { sleep } from '@hydrooj/utils/lib/utils';
import { Context } from '../context';
@@ -141,7 +141,7 @@ export async function apply(ctx: Context) {
collEvent.insertOne({
ack: [id],
event,
payload: JSON.stringify(payload),
payload: BSON.EJSON.stringify(payload),
expire: new Date(Date.now() + 10000),
});
});
@@ -149,8 +149,8 @@ export async function apply(ctx: Context) {
if (process.env.NODE_APP_INSTANCE !== '0') return;
const stream = collEvent.watch();
const handleEvent = async (doc: EventDoc) => {
const payload = JSON.parse(doc.payload);
process.send?.({ type: 'hydro:broadcast', data: { event: doc.event, payload } });
process.send?.({ type: 'hydro:broadcast', data: doc });
const payload = BSON.EJSON.parse(doc.payload);
await (bus.parallel as any)(doc.event, ...payload);
};
stream.on('change', async (change) => {
+4 -4
View File
@@ -1,6 +1,6 @@
/* eslint-disable no-await-in-loop */
import type {
Db, Filter, ObjectId, OnlyFieldsOfType,
import {
BSON, Db, Filter, ObjectId, OnlyFieldsOfType,
} from 'mongodb';
import pm2 from '@hydrooj/utils/lib/locate-pm2';
import type { ProblemSolutionHandler } from '../handler/problem';
@@ -111,10 +111,10 @@ try {
pm2.launchBus((err, bus) => {
if (err) throw new Error();
bus.on('hydro:broadcast', (packet) => {
(app.parallel as any)(packet.data.event, ...packet.data.payload);
(app.parallel as any)(packet.data.event, ...BSON.EJSON.parse(packet.data.payload));
});
app.on('bus/broadcast', (event, payload) => {
process.send({ type: 'hydro:broadcast', data: { event, payload } });
process.send({ type: 'hydro:broadcast', data: { event, payload: BSON.EJSON.stringify(payload) } });
});
console.debug('Using pm2 event bus');
});