judge: bug fixes

This commit is contained in:
undefined committed 2022-09-06 13:02:46 +08:00
1 parent fe0cd78db7
commit 5d0676a5d9
6 files changed
+17 -17

No files matched your search

+2 -2
View File
@@ -88,8 +88,8 @@ export const runFlow = async (ctx: Context, task: Task) => {
};
const runner = task.judgeCase(subtask.cases.find((i) => i.input.endsWith(ctx.meta.hackRejudge)));
const res = await runner(ctx, ctxSubtask, runner);
if (res) ctx.next(res);
if (res.status !== STATUS.STATUS_ACCEPTED) {
if (res) ctx.next({ case: res });
if (res?.status !== STATUS.STATUS_ACCEPTED) {
const totalScore = Math.sum(ctx.config.subtasks.map((i) => i.score));
ctx.end({
status: STATUS.STATUS_HACKED,
+10 -9
View File
@@ -28,16 +28,17 @@ export default class Hydro {
this.config.cookie = this.config.cookie || '';
this.config.last_update_at = this.config.last_update_at || 0;
if (!this.config.server_url.startsWith('http')) this.config.server_url = `http://${this.config.server_url}`;
if (!this.config.server_url.endsWith('/')) this.config.server_url = `${this.config.server_url}/`;
this.getLang = this.getLang.bind(this);
}
get(url) {
return superagent.get(this.config.server_url + url).set('Cookie', this.config.cookie);
get(url: string) {
url = new URL(url, this.config.server_url).toString();
return superagent.get(url).set('Cookie', this.config.cookie);
}
post(url, data) {
return superagent.post(this.config.server_url + url).send(data)
post(url: string, data: any) {
url = new URL(url, this.config.server_url).toString();
return superagent.post(url).send(data)
.set('Cookie', this.config.cookie)
.set('Accept', 'application/json');
}
@@ -51,7 +52,7 @@ export default class Hydro {
async cacheOpen(source: string, files: any[], next?) {
await Lock.acquire(`${this.config.host}/${source}`);
try {
return this._cacheOpen(source, files, next);
return await this._cacheOpen(source, files, next);
} finally {
Lock.release(`${this.config.host}/${source}`);
}
@@ -79,7 +80,7 @@ export default class Hydro {
}
if (filenames.length) {
log.info(`Getting problem data: ${this.config.host}/${source}`);
if (next) next({ message: 'Syncing testdata, please wait...' });
next?.({ message: 'Syncing testdata, please wait...' });
await this.ensureLogin();
const res = await this.post(`/d/${domainId}/judge/files`, {
pid: +pid,
@@ -140,7 +141,7 @@ export default class Hydro {
getNext(t: JudgeTask) {
return (data: Partial<JudgeResultBody>) => {
log.debug('Next: %d %o', data);
log.debug('Next: %o', data);
this.send(t.request.rid, 'next', data);
};
}
@@ -207,7 +208,7 @@ export default class Hydro {
async ensureLogin() {
try {
const res = await this.get('judge/files');
const res = await this.get('judge/files').set('Accept', 'application/json');
// Redirected to /login
if (res.body.url) await this.login();
} catch (e) {
+1 -1
View File
@@ -6,12 +6,12 @@ import { STATUS } from '@hydrooj/utils/lib/status';
import type {
FileInfo, JudgeMeta, JudgeRequest, JudgeResultBody,
} from 'hydrooj';
import { Logger } from 'hydrooj/src/logger';
import readCases from './cases';
import { getConfig } from './config';
import { CompileError, FormatError } from './error';
import { NextFunction, ParsedConfig } from './interface';
import judge from './judge';
import { Logger } from './log';
import { CopyInFile } from './sandbox';
import * as tmpfs from './tmpfs';
import { compilerText, Lock, md5 } from './utils';
+1 -1
View File
@@ -223,7 +223,7 @@ class JudgeConnectionHandler extends ConnectionHandler {
}
async cleanup() {
logger.info('Judge daemon disconnected from ', this.ip);
logger.info('Judge daemon disconnected from ', this.request.ip);
bus.off('system/setting', this.sendLanguageConfig);
if (this.processing) {
await record.reset(this.processing.domainId, this.processing.rid, false);
+1 -2
View File
@@ -435,8 +435,7 @@ export class ProblemDetailHandler extends ContestDetailBaseHandler {
pid,
contest: { $ne: new ObjectID('0'.repeat(24)) },
status: { $ne: [STATUS.STATUS_HACK_SUCCESSFUL, STATUS.STATUS_HACK_UNSUCCESSFUL] },
})
.project({ _id: 1, contest: 1 }).toArray();
}).project({ _id: 1, contest: 1 }).toArray();
const priority = await record.submissionPriority(this.user._id, -rdocs.length * 5 - 50);
await Promise.all(rdocs.map(
(doc) => record.reset(domainId, doc._id, true)
+2 -2
View File
@@ -173,8 +173,8 @@ class RecordDetailHandler extends Handler {
@param('rid', Types.ObjectID)
async postRejudge(domainId: string, rid: ObjectID) {
this.checkPerm(PERM.PERM_REJUDGE);
if ([STATUS.STATUS_HACK_SUCCESSFUL, STATUS.STATUS_HACK_UNSUCCESSFUL].find((i) => i === this.rdoc.status)) {
throw new ForbiddenError('Cannot rejudge hack record.');
if ([STATUS.STATUS_HACK_SUCCESSFUL, STATUS.STATUS_HACK_UNSUCCESSFUL].includes(this.rdoc.status)) {
throw new ForbiddenError('Cannot rejudge a hack record.');
}
const priority = await record.submissionPriority(this.user._id, -20);
const isContest = this.rdoc.contest && this.rdoc.contest.toString() !== '000000000000000000000000';