mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 09:46:28 +08:00
Hello airbnb
This commit is contained in:
1 parent
f9468536de
commit
8c195661d7
78 files changed
+2032
-1471
No files matched your search
+33
-25
@@ -1,16 +1,17 @@
|
||||
const
|
||||
{ PERM_JUDGE } = require('../permission'),
|
||||
record = require('../model/record'),
|
||||
problem = require('../model/problem'),
|
||||
bus = require('../service/bus'),
|
||||
queue = require('../service/queue'),
|
||||
{ Route, Handler, Connection, ConnectionHandler } = require('../service/server');
|
||||
const { PERM_JUDGE } = require('../permission');
|
||||
const record = require('../model/record');
|
||||
const problem = require('../model/problem');
|
||||
const bus = require('../service/bus');
|
||||
const queue = require('../service/queue');
|
||||
const {
|
||||
Route, Handler, Connection, ConnectionHandler,
|
||||
} = require('../service/server');
|
||||
|
||||
queue.assert('judge');
|
||||
|
||||
async function next(body) {
|
||||
let rdoc = await record.get(body.rid);
|
||||
let $set = {};
|
||||
const $set = {};
|
||||
if (body.case) {
|
||||
rdoc.cases.push(body.case);
|
||||
$set.cases = rdoc.cases;
|
||||
@@ -32,7 +33,7 @@ async function next(body) {
|
||||
}
|
||||
async function end(body) {
|
||||
let rdoc = await record.get(body.rid);
|
||||
let $set = {};
|
||||
const $set = {};
|
||||
if (body.case) {
|
||||
rdoc.cases.push(body.case);
|
||||
$set.cases = rdoc.cases;
|
||||
@@ -59,29 +60,33 @@ class JudgeHandler extends Handler {
|
||||
async prepare() {
|
||||
this.checkPerm(PERM_JUDGE);
|
||||
}
|
||||
|
||||
async get({ check = false }) {
|
||||
this.response.body = {};
|
||||
if (check) return;
|
||||
let rid = await queue.get('judge', false);
|
||||
const rid = await queue.get('judge', false);
|
||||
if (rid) {
|
||||
let rdoc = await record.get(rid);
|
||||
let pdoc = await problem.getById(rdoc.pid);
|
||||
let task = {
|
||||
const rdoc = await record.get(rid);
|
||||
const pdoc = await problem.getById(rdoc.pid);
|
||||
const task = {
|
||||
event: 'judge',
|
||||
rid, type: 0,
|
||||
rid,
|
||||
type: 0,
|
||||
pid: rdoc.pid,
|
||||
data: pdoc.data,
|
||||
lang: rdoc.lang,
|
||||
code: rdoc.code
|
||||
code: rdoc.code,
|
||||
};
|
||||
this.response.body = { task };
|
||||
}
|
||||
}
|
||||
async post_next() {
|
||||
|
||||
async postNext() {
|
||||
await next(this.request.body);
|
||||
this.response.body = {};
|
||||
}
|
||||
async post_end() {
|
||||
|
||||
async postEnd() {
|
||||
await end(this.request.body);
|
||||
this.response.body = {};
|
||||
}
|
||||
@@ -90,26 +95,29 @@ class JudgeConnectionHandler extends ConnectionHandler {
|
||||
async prepare() {
|
||||
this.checkPerm(PERM_JUDGE);
|
||||
}
|
||||
|
||||
async message(msg) {
|
||||
if (msg.key == 'next') await next(msg);
|
||||
else if (msg.key == 'end') {
|
||||
if (msg.key === 'next') await next(msg);
|
||||
else if (msg.key === 'end') {
|
||||
await end({ judger: this.user._id, ...msg });
|
||||
this.processing = null;
|
||||
let rid = await queue.get('judge');
|
||||
let rdoc = await record.get(rid);
|
||||
let pdoc = await problem.getById(rdoc.pid);
|
||||
let task = {
|
||||
const rid = await queue.get('judge');
|
||||
const rdoc = await record.get(rid);
|
||||
const pdoc = await problem.getById(rdoc.pid);
|
||||
const task = {
|
||||
event: 'judge',
|
||||
rid, type: 0,
|
||||
rid,
|
||||
type: 0,
|
||||
pid: rdoc.pid,
|
||||
data: pdoc.data,
|
||||
lang: rdoc.lang,
|
||||
code: rdoc.code
|
||||
code: rdoc.code,
|
||||
};
|
||||
this.send({ task });
|
||||
this.processing = task.rid;
|
||||
}
|
||||
}
|
||||
|
||||
async cleanup() {
|
||||
if (this.processing) {
|
||||
await record.reset(this.processing);
|
||||
|
||||
Reference in new issue
Block a user