mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
core: add task.getDelay() method
This commit is contained in:
1 parent
775605f812
commit
5bbce72a68
6 files changed
+17
-4
No files matched your search
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "hydrooj",
|
"name": "hydrooj",
|
||||||
"version": "2.21.9",
|
"version": "2.21.10",
|
||||||
"bin": "bin/hydrooj.js",
|
"bin": "bin/hydrooj.js",
|
||||||
"main": "dist/loader.js",
|
"main": "dist/loader.js",
|
||||||
"typings": "dist/loader.d.ts",
|
"typings": "dist/loader.d.ts",
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import problem from '../model/problem';
|
|||||||
import record from '../model/record';
|
import record from '../model/record';
|
||||||
import * as contest from '../model/contest';
|
import * as contest from '../model/contest';
|
||||||
import user from '../model/user';
|
import user from '../model/user';
|
||||||
|
import TaskModel from '../model/task';
|
||||||
import paginate from '../lib/paginate';
|
import paginate from '../lib/paginate';
|
||||||
import * as bus from '../service/bus';
|
import * as bus from '../service/bus';
|
||||||
import {
|
import {
|
||||||
@@ -66,7 +67,10 @@ class RecordListHandler extends RecordHandler {
|
|||||||
filterUidOrName: uidOrName,
|
filterUidOrName: uidOrName,
|
||||||
};
|
};
|
||||||
if (this.user.hasPriv(PRIV.PRIV_VIEW_JUDGE_STATISTICS)) {
|
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' }),
|
||||||
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -48,6 +48,13 @@ class TaskModel {
|
|||||||
return null;
|
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) {
|
static async consume(query: any, cb: Function) {
|
||||||
let isRunning = false;
|
let isRunning = false;
|
||||||
const interval = setInterval(async () => {
|
const interval = setInterval(async () => {
|
||||||
|
|||||||
@@ -169,12 +169,13 @@ env.addGlobal('datetimeSpan', misc.datetimeSpan);
|
|||||||
env.addGlobal('paginate', misc.paginate);
|
env.addGlobal('paginate', misc.paginate);
|
||||||
env.addGlobal('size', misc.size);
|
env.addGlobal('size', misc.size);
|
||||||
env.addGlobal('gravatar', misc.gravatar);
|
env.addGlobal('gravatar', misc.gravatar);
|
||||||
|
env.addGlobal('formatSeconds', misc.formatSeconds);
|
||||||
env.addGlobal('model', global.Hydro.model);
|
env.addGlobal('model', global.Hydro.model);
|
||||||
env.addGlobal('ui', global.Hydro.ui);
|
env.addGlobal('ui', global.Hydro.ui);
|
||||||
env.addGlobal('isIE', (str) => str.includes('MSIE') || str.includes('rv:11.0'));
|
env.addGlobal('isIE', (str) => str.includes('MSIE') || str.includes('rv:11.0'));
|
||||||
env.addGlobal('set', (obj, key, val) => {
|
env.addGlobal('set', (obj, key, val) => {
|
||||||
if (val !== undefined) obj[key] = val;
|
if (val !== undefined) obj[key] = val;
|
||||||
else obj = { ...obj, key };
|
else Object.assign(obj, key);
|
||||||
return '';
|
return '';
|
||||||
});
|
});
|
||||||
env.addGlobal('findSubModule', (prefix) => {
|
env.addGlobal('findSubModule', (prefix) => {
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@hydrooj/ui-default",
|
"name": "@hydrooj/ui-default",
|
||||||
"version": "4.5.7",
|
"version": "4.5.8",
|
||||||
"author": "undefined <i@undefined.moe>",
|
"author": "undefined <i@undefined.moe>",
|
||||||
"license": "AGPL-3.0",
|
"license": "AGPL-3.0",
|
||||||
"main": "hydro.js",
|
"main": "hydro.js",
|
||||||
|
|||||||
@@ -93,6 +93,7 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="section__body">
|
<div class="section__body">
|
||||||
<dl class="large horizontal">
|
<dl class="large horizontal">
|
||||||
|
<dt>{{ _('Delay')}}</dt><dd>{{ formatSeconds(statistics.delay[0] / 1000) }}</dd>
|
||||||
<dt>{{ _('5 Min')}}</dt><dd>{{ statistics['d5min'] }}</dd>
|
<dt>{{ _('5 Min')}}</dt><dd>{{ statistics['d5min'] }}</dd>
|
||||||
<dt>{{ _('1 Hour')}}</dt><dd>{{ statistics['d1h'] }}</dd>
|
<dt>{{ _('1 Hour')}}</dt><dd>{{ statistics['d1h'] }}</dd>
|
||||||
<dt>{{ _('Day') }}</dt><dd>{{ statistics['day'] }}</dd>
|
<dt>{{ _('Day') }}</dt><dd>{{ statistics['day'] }}</dd>
|
||||||
|
|||||||
Reference in new issue
Block a user