core: add task.getDelay() method

This commit is contained in:
undefined committed 2021-04-06 17:40:58 +08:00
1 parent 775605f812
commit 5bbce72a68
6 files changed
+17 -4

No files matched your search

+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "hydrooj",
"version": "2.21.9",
"version": "2.21.10",
"bin": "bin/hydrooj.js",
"main": "dist/loader.js",
"typings": "dist/loader.d.ts",
+5 -1
View File
@@ -7,6 +7,7 @@ import problem from '../model/problem';
import record from '../model/record';
import * as contest from '../model/contest';
import user from '../model/user';
import TaskModel from '../model/task';
import paginate from '../lib/paginate';
import * as bus from '../service/bus';
import {
@@ -66,7 +67,10 @@ class RecordListHandler extends RecordHandler {
filterUidOrName: uidOrName,
};
if (this.user.hasPriv(PRIV.PRIV_VIEW_JUDGE_STATISTICS)) {
this.response.body.statistics = await record.stat(all ? undefined : domainId);
this.response.body.statistics = {
...await record.stat(all ? undefined : domainId),
delay: await TaskModel.getDelay({ type: 'judge' }),
};
}
}
}
+7
View File
@@ -48,6 +48,13 @@ class TaskModel {
return null;
}
static async getDelay(query?: FilterQuery<Task>) {
const now = new Date();
const [res] = await coll.find(query).sort({ executeAfter: 1 }).limit(1).toArray();
if (res) return [Math.max(0, now.getTime() - res.executeAfter.getTime()), res.executeAfter];
return [0, now];
}
static async consume(query: any, cb: Function) {
let isRunning = false;
const interval = setInterval(async () => {