core: fix websocket event push

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

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

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

@ -67,7 +67,7 @@ class MongoService {
const coll = this.db.collection(c.name); const coll = this.db.collection(c.name);
const indexes = await coll.listIndexes().toArray(); const indexes = await coll.listIndexes().toArray();
for (const i of indexes) { for (const i of indexes) {
if (!i.expireAfterSeconds) continue; if (typeof i.expireAfterSeconds !== 'number') continue;
const key = Object.keys(i.key)[0]; const key = Object.keys(i.key)[0];
await coll.deleteMany({ [key]: { $lt: new Date(Date.now() - i.expireAfterSeconds * 1000) } }); 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); await bus.parallel('connection/active', h);
} catch (e) { } catch (e) {
await h.onerror(e); await h.onerror(e);
} finally {
disposables.forEach((d) => d());
} }
}); });
return router.disposeLastOp; return router.disposeLastOp;

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

Loading…
Cancel
Save