diff --git a/packages/hydrooj/src/entry/worker.ts b/packages/hydrooj/src/entry/worker.ts index 4a57ed837..735219f17 100644 --- a/packages/hydrooj/src/entry/worker.ts +++ b/packages/hydrooj/src/entry/worker.ts @@ -44,7 +44,7 @@ export async function apply(ctx: Context) { await ctx.root.start(); require('../lib/index'); await lib(pending, fail, ctx); - require('../service/monitor'); + ctx.plugin(require('../service/monitor')); await service(pending, fail, ctx); await builtinModel(ctx); await model(pending, fail, ctx); diff --git a/packages/hydrooj/src/interface.ts b/packages/hydrooj/src/interface.ts index 7a972e02d..f81f08872 100644 --- a/packages/hydrooj/src/interface.ts +++ b/packages/hydrooj/src/interface.ts @@ -649,7 +649,6 @@ export interface HydroService { /** @deprecated */ bus: Context, db: typeof import('./service/db').default, - monitor: typeof import('./service/monitor'), server: typeof import('./service/server'), storage: typeof import('./service/storage').default, } diff --git a/packages/hydrooj/src/service/monitor.ts b/packages/hydrooj/src/service/monitor.ts index f2bee6dd8..328f6cff9 100644 --- a/packages/hydrooj/src/service/monitor.ts +++ b/packages/hydrooj/src/service/monitor.ts @@ -2,6 +2,7 @@ import { dump } from 'js-yaml'; import superagent from 'superagent'; import type { StatusUpdate } from '@hydrooj/utils/lib/sysinfo'; import * as sysinfo from '@hydrooj/utils/lib/sysinfo'; +import { Context } from '../context'; import { Logger } from '../logger'; import * as bus from './bus'; import db from './db'; @@ -90,8 +91,9 @@ export async function updateJudge(args) { ); } -if (process.env.NODE_APP_INSTANCE === '0') { - bus.on('ready', async () => { +export function apply(ctx: Context) { + if (process.env.NODE_APP_INSTANCE !== '0') return; + ctx.on('app/started', async () => { sysinfo.get().then((info) => { coll.updateOne( { mid: info.mid, type: 'server' }, @@ -103,5 +105,3 @@ if (process.env.NODE_APP_INSTANCE === '0') { }); }); } - -global.Hydro.service.monitor = { feedback, update, updateJudge };