core: fix websocket event push

pull/501/head
undefined 2 years ago
parent 518915ceab
commit f834d9ca87

@ -1,6 +1,6 @@
{
"name": "hydrooj",
"version": "4.7.0",
"version": "4.7.1",
"bin": "bin/hydrooj.js",
"main": "src/plugin-api",
"module": "src/plugin-api",

@ -1,4 +1,5 @@
import { hostname } from 'os';
import cac from 'cac';
import { FilterQuery, ObjectID } from 'mongodb';
import { nanoid } from 'nanoid';
import { sleep } from '@hydrooj/utils/lib/utils';
@ -11,6 +12,7 @@ import db from '../service/db';
const logger = new Logger('model/task');
const coll = db.collection('task');
const collEvent = db.collection('event');
const argv = cac().parse();
async function getFirst(query: FilterQuery<Task>) {
if (process.env.CI) return null;
@ -133,6 +135,7 @@ export async function apply(ctx: Context) {
{ expire: { $gt: new Date() }, ack: { $nin: [id] } },
{ $push: { ack: id } },
);
if (argv.options.showEvent) logger.info('Event: %o', res.value);
// eslint-disable-next-line no-await-in-loop
await (res.value ? handleEvent(res.value) : sleep(500));
}

@ -67,7 +67,7 @@ class MongoService {
const coll = this.db.collection(c.name);
const indexes = await coll.listIndexes().toArray();
for (const i of indexes) {
if (!i.expireAfterSeconds) continue;
if (typeof i.expireAfterSeconds !== 'number') continue;
const key = Object.keys(i.key)[0];
await coll.deleteMany({ [key]: { $lt: new Date(Date.now() - i.expireAfterSeconds * 1000) } });
}

@ -390,8 +390,6 @@ export function Connection(
await bus.parallel('connection/active', h);
} catch (e) {
await h.onerror(e);
} finally {
disposables.forEach((d) => d());
}
});
return router.disposeLastOp;

@ -71,7 +71,6 @@ const build = async (contents: string) => {
};
export async function buildUI() {
console.log(1, 'building');
const start = Date.now();
let totalSize = 0;
const entryPoints: string[] = [];

Loading…
Cancel
Save