mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 09:46:28 +08:00
use record.judge
This commit is contained in:
3 files changed
+22
-54
No files matched your search
@@ -7,7 +7,8 @@ import { Filter, ObjectId } from 'mongodb';
|
|||||||
import Schema from 'schemastery';
|
import Schema from 'schemastery';
|
||||||
import { Time } from '@hydrooj/utils';
|
import { Time } from '@hydrooj/utils';
|
||||||
import {
|
import {
|
||||||
CannotEditSuperAdminError, ContestNotFoundError, NotLaunchedByPM2Error, ProblemNotFoundError, RecordNotFoundError, UserNotFoundError, ValidationError,
|
CannotEditSuperAdminError, ContestNotFoundError, NotLaunchedByPM2Error, ProblemNotFoundError,
|
||||||
|
RecordNotFoundError, UserNotFoundError, ValidationError,
|
||||||
} from '../error';
|
} from '../error';
|
||||||
import { RecordDoc } from '../interface';
|
import { RecordDoc } from '../interface';
|
||||||
import { Logger } from '../logger';
|
import { Logger } from '../logger';
|
||||||
@@ -424,7 +425,7 @@ class SystemRejudgeHandler extends SystemHandler {
|
|||||||
q._id = { ...q._id, $lte: Time.getObjectID(endAt) };
|
q._id = { ...q._id, $lte: Time.getObjectID(endAt) };
|
||||||
}
|
}
|
||||||
if (beginAt && endAt && beginAt.isSameOrAfter(endAt)) throw new ValidationError('duration');
|
if (beginAt && endAt && beginAt.isSameOrAfter(endAt)) throw new ValidationError('duration');
|
||||||
const rids = await record.getMulti(domainId, q).project({ _id: 1 }).toArray();
|
const rdocs = await record.getMulti(domainId, q).project({ _id: 1, contest: 1 }).toArray();
|
||||||
if (_type === 'preview') {
|
if (_type === 'preview') {
|
||||||
this.response.body = {
|
this.response.body = {
|
||||||
uidOrName,
|
uidOrName,
|
||||||
@@ -438,60 +439,26 @@ class SystemRejudgeHandler extends SystemHandler {
|
|||||||
status: status.join(','),
|
status: status.join(','),
|
||||||
highPriority,
|
highPriority,
|
||||||
apply: _apply,
|
apply: _apply,
|
||||||
recordLength: rids.length,
|
recordLength: rdocs.length,
|
||||||
rrdocs: await record.getMultiRejudgeTask({}),
|
rrdocs: await record.getMultiRejudgeTask({}),
|
||||||
};
|
};
|
||||||
this.response.template = 'manage_rejudge.html';
|
this.response.template = 'manage_rejudge.html';
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const rid = await record.add(domainId, -1, this.user._id, '-', 'rejudge', false, {
|
const rid = await record.addRejudgeTask(domainId, {
|
||||||
input: JSON.stringify({
|
owner: this.user._id,
|
||||||
domainId,
|
|
||||||
rids: rids.map((i) => i._id.toString()),
|
|
||||||
highPriority,
|
|
||||||
apply: _apply,
|
|
||||||
}),
|
|
||||||
type: 'rejudge',
|
|
||||||
});
|
|
||||||
const args = global.Hydro.script['rejudge'].validate({
|
|
||||||
rrid: rid.toHexString(),
|
|
||||||
domainId,
|
|
||||||
rids: rids.map((i) => i._id.toString()),
|
|
||||||
highPriority,
|
|
||||||
apply: _apply,
|
apply: _apply,
|
||||||
|
rids: rdocs.map((i) => i._id),
|
||||||
});
|
});
|
||||||
const report = (data) => judge.next({ domainId, rid, ...data });
|
const priority = await record.submissionPriority(this.user._id, -10000 - rdocs.length * 5 - 50);
|
||||||
report({ message: 'Start rejudge', status: STATUS.STATUS_JUDGING });
|
await record.reset(domainId, rdocs.map((rdoc) => rdoc._id), true);
|
||||||
const start = Date.now();
|
await Promise.all([
|
||||||
// Maybe async?
|
record.judge(domainId, rdocs.filter((i) => i.contest).map((i) => i._id), priority, { detail: false },
|
||||||
global.Hydro.script['rejudge'].run(args, report)
|
{ rejudge: _apply ? true : 'controlled' }),
|
||||||
.then((ret: any) => {
|
record.judge(domainId, rdocs.filter((i) => !i.contest).map((i) => i._id), priority, {},
|
||||||
const time = new Date().getTime() - start;
|
{ rejudge: _apply ? true : 'controlled' }),
|
||||||
judge.end({
|
]);
|
||||||
domainId,
|
this.response.redirect = this.url('manage_rejudge_detail', { rid });
|
||||||
rid: rid.toHexString(),
|
|
||||||
status: STATUS.STATUS_ACCEPTED,
|
|
||||||
message: inspect(ret, false, 10, true),
|
|
||||||
judger: 1,
|
|
||||||
time,
|
|
||||||
memory: 0,
|
|
||||||
});
|
|
||||||
})
|
|
||||||
.catch((err: Error) => {
|
|
||||||
const time = new Date().getTime() - start;
|
|
||||||
logger.error(err);
|
|
||||||
judge.end({
|
|
||||||
domainId,
|
|
||||||
rid: rid.toHexString(),
|
|
||||||
status: STATUS.STATUS_SYSTEM_ERROR,
|
|
||||||
message: `${err.message} \n${(err as any).params || []} \n${err.stack} `,
|
|
||||||
judger: 1,
|
|
||||||
time,
|
|
||||||
memory: 0,
|
|
||||||
});
|
|
||||||
});
|
|
||||||
this.response.body = { rid };
|
|
||||||
this.response.redirect = this.url('manage_rejudge_detail', { rid: rid.toHexString() });
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -230,12 +230,12 @@ export interface RecordStatDoc {
|
|||||||
|
|
||||||
export interface RecordRejudgeDoc {
|
export interface RecordRejudgeDoc {
|
||||||
_id: ObjectId;
|
_id: ObjectId;
|
||||||
|
domainId: string;
|
||||||
owner: number;
|
owner: number;
|
||||||
reason: string;
|
|
||||||
apply: boolean;
|
apply: boolean;
|
||||||
finishAt: Date;
|
finishAt?: Date;
|
||||||
rids: ObjectId[];
|
rids: ObjectId[];
|
||||||
changes: {
|
changes?: {
|
||||||
rid: ObjectId;
|
rid: ObjectId;
|
||||||
old: number;
|
old: number;
|
||||||
new: number;
|
new: number;
|
||||||
|
|||||||
@@ -290,8 +290,9 @@ export default class RecordModel {
|
|||||||
return RecordModel.collRejudge.findOne({ _id });
|
return RecordModel.collRejudge.findOne({ _id });
|
||||||
}
|
}
|
||||||
|
|
||||||
static async addRejudgeTask(doc: RecordRejudgeDoc) {
|
static async addRejudgeTask(domainId: string, doc: Pick<RecordRejudgeDoc, 'owner' | 'apply' | 'rids' | 'changes'>) {
|
||||||
await RecordModel.collRejudge.insertOne(doc);
|
const res = await RecordModel.collRejudge.insertOne({ _id: new ObjectId(), domainId, ...doc });
|
||||||
|
return res.insertedId;
|
||||||
}
|
}
|
||||||
|
|
||||||
static async pushRejudgeResult(rrid: ObjectId, result: { rid: ObjectId, old: number, new: number }) {
|
static async pushRejudgeResult(rrid: ObjectId, result: { rid: ObjectId, old: number, new: number }) {
|
||||||
|
|||||||
Reference in new issue
Block a user