core: 优化钩子逻辑

This commit is contained in:
undefined committed 2020-09-06 11:31:49 +08:00
1 parent 03dc8903e2
commit f2f0212947
27 files changed
+205 -124

No files matched your search

+10 -11
View File
@@ -1,5 +1,6 @@
import cluster from 'cluster';
import * as db from './db';
import * as bus from './bus';
import * as sysinfo from '../lib/sysinfo';
const coll = db.collection('status');
@@ -24,17 +25,15 @@ export function updateJudger(args) {
}
if (cluster.isMaster) {
global.Hydro.postInit.push(
async () => {
const info = await sysinfo.get();
await coll.updateOne(
{ mid: info.mid, type: 'server' },
{ $set: { ...info, updateAt: new Date(), type: 'server' } },
{ upsert: true },
);
setInterval(update, 60 * 1000);
},
);
bus.on('app/started', async () => {
const info = await sysinfo.get();
await coll.updateOne(
{ mid: info.mid, type: 'server' },
{ $set: { ...info, updateAt: new Date(), type: 'server' } },
{ upsert: true },
);
setInterval(update, 60 * 1000);
});
}
global.Hydro.service.monitor = { update, updateJudger };