mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
升级queue为task
This commit is contained in:
1 parent
e7ce8c1f02
commit
5d7f57334f
14 files changed
+145
-130
No files matched your search
@@ -10,4 +10,7 @@ module.exports = {
|
||||
token: require('./token'),
|
||||
training: require('./training'),
|
||||
user: require('./user'),
|
||||
task: require('./task'),
|
||||
message: require('./message'),
|
||||
setting: require('./setting'),
|
||||
};
|
||||
+34
-1
@@ -1,7 +1,9 @@
|
||||
const _ = require('lodash');
|
||||
const { ObjectID } = require('bson');
|
||||
const { RecordNotFoundError } = require('../error');
|
||||
const { STATUS_WAITING } = require('./builtin').STATUS;
|
||||
const task = require('./task');
|
||||
const problem = require('./problem');
|
||||
const { RecordNotFoundError } = require('../error');
|
||||
const db = require('../service/db.js');
|
||||
|
||||
const coll = db.collection('record');
|
||||
@@ -75,6 +77,35 @@ function getUserInProblemMulti(uid, pid) {
|
||||
return coll.find({ owner: uid, pid });
|
||||
}
|
||||
|
||||
async function judge(rid) {
|
||||
const rdoc = await get(rid);
|
||||
const pdoc = await problem.getById(rdoc.pid);
|
||||
await task.add({
|
||||
event: 'judge',
|
||||
rid,
|
||||
type: 0,
|
||||
pid: rdoc.pid,
|
||||
data: pdoc.data,
|
||||
lang: rdoc.lang,
|
||||
code: rdoc.code,
|
||||
});
|
||||
}
|
||||
|
||||
async function rejudge(rid) {
|
||||
await reset(rid);
|
||||
const rdoc = await get(rid);
|
||||
const pdoc = await problem.getById(rdoc.pid);
|
||||
await task.add({
|
||||
event: 'judge',
|
||||
rid,
|
||||
type: 0,
|
||||
pid: rdoc.pid,
|
||||
data: pdoc.data,
|
||||
lang: rdoc.lang,
|
||||
code: rdoc.code,
|
||||
});
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
add,
|
||||
get,
|
||||
@@ -84,4 +115,6 @@ module.exports = {
|
||||
reset,
|
||||
getList,
|
||||
getUserInProblemMulti,
|
||||
judge,
|
||||
rejudge,
|
||||
};
|
||||
@@ -0,0 +1,30 @@
|
||||
const db = require('../service/db.js');
|
||||
|
||||
const coll = db.collection('task');
|
||||
|
||||
async function add(task) {
|
||||
const res = await coll.insertOne(task);
|
||||
return res.insertedId;
|
||||
}
|
||||
|
||||
function get(_id) {
|
||||
return coll.findOne({ _id });
|
||||
}
|
||||
|
||||
function count(query) {
|
||||
return coll.find(query).count();
|
||||
}
|
||||
|
||||
function del(_id) {
|
||||
return coll.deleteOne({ _id });
|
||||
}
|
||||
|
||||
async function getFirst(query) {
|
||||
const res = await coll.find(query).sort('_id', 1).limit(1).toArray();
|
||||
await coll.deleteOne({ _id: res[0]._id });
|
||||
return res[0];
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
add, get, del, count, getFirst,
|
||||
};
|
||||
Reference in new issue
Block a user