mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
core: merge rdoc into task
This commit is contained in:
3 files changed
+26
-24
No files matched your search
@@ -78,7 +78,7 @@ export async function next(body: Partial<JudgeResultBody>) {
|
|||||||
$set, $push, $unset, $inc,
|
$set, $push, $unset, $inc,
|
||||||
} = processPayload(body);
|
} = processPayload(body);
|
||||||
const rdoc = await record.update(body.domainId, body.rid, $set, $push, $unset, $inc);
|
const rdoc = await record.update(body.domainId, body.rid, $set, $push, $unset, $inc);
|
||||||
bus.broadcast('record/change', rdoc, $set, $push, body);
|
if (rdoc) bus.broadcast('record/change', rdoc, $set, $push, body);
|
||||||
return rdoc;
|
return rdoc;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -144,10 +144,9 @@ export async function end(body: Partial<JudgeResultBody>) {
|
|||||||
const $unset: any = { progress: '' };
|
const $unset: any = { progress: '' };
|
||||||
$set.judgeAt = new Date();
|
$set.judgeAt = new Date();
|
||||||
$set.judger = body.judger ?? 1;
|
$set.judger = body.judger ?? 1;
|
||||||
let rdoc = await record.update(body.domainId, body.rid, $set, $push, $unset);
|
const rdoc = await record.update(body.domainId, body.rid, $set, $push, $unset);
|
||||||
|
if (rdoc) bus.broadcast('record/change', rdoc, null, null, body); // trigger a full update
|
||||||
await postJudge(rdoc);
|
await postJudge(rdoc);
|
||||||
rdoc = await record.get(body.rid);
|
|
||||||
bus.broadcast('record/change', rdoc, null, null, body); // trigger a full update
|
|
||||||
return rdoc;
|
return rdoc;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -246,20 +245,17 @@ export class JudgeConnectionHandler extends ConnectionHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async newTask(t: Task) {
|
async newTask(t: Task) {
|
||||||
const rdoc = await record.get(t.domainId, t.rid);
|
const rid = t.rid.toHexString();
|
||||||
if (!rdoc) return;
|
|
||||||
|
|
||||||
const rid = rdoc._id.toHexString();
|
|
||||||
let resolve: (_: any) => void;
|
let resolve: (_: any) => void;
|
||||||
const p = new Promise((r) => { resolve = r; });
|
const p = new Promise((r) => { resolve = r; });
|
||||||
this.tasks[rid] = {
|
this.tasks[rid] = {
|
||||||
queue: new PQueue({ concurrency: 1 }),
|
queue: new PQueue({ concurrency: 1 }),
|
||||||
domainId: rdoc.domainId,
|
domainId: t.domainId,
|
||||||
resolve,
|
resolve,
|
||||||
t,
|
t,
|
||||||
};
|
};
|
||||||
this.send({ task: { ...rdoc, ...t } });
|
this.send({ task: t });
|
||||||
this.tasks[rid].queue.add(() => next({ status: STATUS.STATUS_FETCHED, domainId: rdoc.domainId, rid: rdoc._id }));
|
this.tasks[rid].queue.add(() => next({ status: STATUS.STATUS_FETCHED, domainId: t.domainId, rid: t.rid }));
|
||||||
await p;
|
await p;
|
||||||
delete this.tasks[rid];
|
delete this.tasks[rid];
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
import { sum } from 'lodash';
|
import { sum } from 'lodash';
|
||||||
import moment from 'moment-timezone';
|
import moment from 'moment-timezone';
|
||||||
import {
|
import {
|
||||||
Filter, MatchKeysAndValues,
|
Filter, FindOptions, MatchKeysAndValues,
|
||||||
ObjectId, OnlyFieldsOfType, PushOperator, UpdateFilter,
|
ObjectId, OnlyFieldsOfType, PushOperator, UpdateFilter,
|
||||||
} from 'mongodb';
|
} from 'mongodb';
|
||||||
import { Context } from '../context';
|
import { Context } from '../context';
|
||||||
@@ -78,15 +78,23 @@ export default class RecordModel {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
static async judge(domainId: string, rids: MaybeArray<ObjectId>, priority = 0, config: ProblemConfigFile = {}, meta: Partial<JudgeMeta> = {}) {
|
static async judge(
|
||||||
rids = rids instanceof Array ? rids : [rids];
|
domainId: string, rids: MaybeArray<ObjectId> | RecordDoc, priority = 0,
|
||||||
if (!rids.length) return null;
|
config: ProblemConfigFile = {}, meta: Partial<JudgeMeta> = {},
|
||||||
const rdocs = await RecordModel.getMulti(domainId, { _id: { $in: rids } }).toArray();
|
) {
|
||||||
|
let rdocs: RecordDoc[];
|
||||||
|
const _rids = rids instanceof Array ? rids
|
||||||
|
: (rids instanceof ObjectId) ? [rids]
|
||||||
|
: [rids._id];
|
||||||
|
if (!_rids.length) return null;
|
||||||
|
if (rids instanceof Array || rids instanceof ObjectId || ObjectId.isValid(rids.toString())) {
|
||||||
|
rdocs = await RecordModel.getMulti(domainId, { _id: { $in: _rids } }, { readPreference: 'primary' }).toArray();
|
||||||
|
} else rdocs = [rids];
|
||||||
if (!rdocs.length) return null;
|
if (!rdocs.length) return null;
|
||||||
let source = `${domainId}/${rdocs[0].pid}`;
|
let source = `${domainId}/${rdocs[0].pid}`;
|
||||||
let [pdoc] = await Promise.all([
|
let [pdoc] = await Promise.all([
|
||||||
problem.get(domainId, rdocs[0].pid),
|
problem.get(domainId, rdocs[0].pid),
|
||||||
task.deleteMany({ rid: { $in: rids } }),
|
task.deleteMany({ rid: { $in: _rids } }),
|
||||||
]);
|
]);
|
||||||
if (!pdoc) throw new ProblemNotFoundError(domainId, rdocs[0].pid);
|
if (!pdoc) throw new ProblemNotFoundError(domainId, rdocs[0].pid);
|
||||||
if (pdoc.reference) {
|
if (pdoc.reference) {
|
||||||
@@ -102,8 +110,8 @@ export default class RecordModel {
|
|||||||
if (pdoc.config.type === 'remote_judge' && rdoc.contest?.toHexString() !== '0'.repeat(24)) type = 'remotejudge';
|
if (pdoc.config.type === 'remote_judge' && rdoc.contest?.toHexString() !== '0'.repeat(24)) type = 'remotejudge';
|
||||||
else if (meta?.type === 'generate') type = 'generate';
|
else if (meta?.type === 'generate') type = 'generate';
|
||||||
return ({
|
return ({
|
||||||
|
...rdoc,
|
||||||
...(pdoc.config as any), // TODO deprecate this
|
...(pdoc.config as any), // TODO deprecate this
|
||||||
lang: rdoc.lang,
|
|
||||||
priority,
|
priority,
|
||||||
type,
|
type,
|
||||||
rid: rdoc._id,
|
rid: rdoc._id,
|
||||||
@@ -167,7 +175,7 @@ export default class RecordModel {
|
|||||||
bus.broadcast('record/change', data);
|
bus.broadcast('record/change', data);
|
||||||
if (addTask) {
|
if (addTask) {
|
||||||
const priority = await RecordModel.submissionPriority(uid, args.type === 'pretest' ? -20 : (isContest ? 50 : 0));
|
const priority = await RecordModel.submissionPriority(uid, args.type === 'pretest' ? -20 : (isContest ? 50 : 0));
|
||||||
await RecordModel.judge(domainId, res.insertedId, priority, isContest ? { detail: false } : {}, {
|
await RecordModel.judge(domainId, data, priority, isContest ? { detail: false } : {}, {
|
||||||
type: args.type,
|
type: args.type,
|
||||||
rejudge: data.rejudged,
|
rejudge: data.rejudged,
|
||||||
});
|
});
|
||||||
@@ -175,9 +183,9 @@ export default class RecordModel {
|
|||||||
return res.insertedId;
|
return res.insertedId;
|
||||||
}
|
}
|
||||||
|
|
||||||
static getMulti(domainId: string, query: any) {
|
static getMulti(domainId: string, query: any, options?: FindOptions) {
|
||||||
if (domainId) query = { domainId, ...query };
|
if (domainId) query = { domainId, ...query };
|
||||||
return RecordModel.coll.find(query);
|
return RecordModel.coll.find(query, options);
|
||||||
}
|
}
|
||||||
|
|
||||||
static getMultiStat(domainId: string, query: any, sortBy: any = { _id: -1 }) {
|
static getMultiStat(domainId: string, query: any, sortBy: any = { _id: -1 }) {
|
||||||
@@ -208,7 +216,7 @@ export default class RecordModel {
|
|||||||
);
|
);
|
||||||
return res.value || null;
|
return res.value || null;
|
||||||
}
|
}
|
||||||
return await RecordModel.get(domainId, _id);
|
return await RecordModel.coll.findOne({ _id }, { readPreference: 'primary' });
|
||||||
}
|
}
|
||||||
|
|
||||||
static async updateMulti(
|
static async updateMulti(
|
||||||
|
|||||||
@@ -42,8 +42,6 @@ class AccountService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async judge(task) {
|
async judge(task) {
|
||||||
const rdoc = await RecordModel.get(task.domainId, task.rid);
|
|
||||||
task = Object.assign(rdoc, task);
|
|
||||||
const next = (payload) => JudgeHandler.next({ ...payload, rid: task.rid, domainId: task.domainId });
|
const next = (payload) => JudgeHandler.next({ ...payload, rid: task.rid, domainId: task.domainId });
|
||||||
const end = (payload) => JudgeHandler.end({ ...payload, rid: task.rid, domainId: task.domainId });
|
const end = (payload) => JudgeHandler.end({ ...payload, rid: task.rid, domainId: task.domainId });
|
||||||
await next({ status: STATUS.STATUS_FETCHED });
|
await next({ status: STATUS.STATUS_FETCHED });
|
||||||
|
|||||||
Reference in new issue
Block a user