mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-17 17:36:08 +08:00
core: support trace on broadcast
This commit is contained in:
4 files changed
+7
-3
No files matched your search
@@ -61,7 +61,9 @@ export class ApiMixin extends Service {
|
||||
setImmediate = T(setImmediate, clearImmediate);
|
||||
provideModule = T(provideModule);
|
||||
injectUI = T(inject);
|
||||
broadcast = (event: keyof EventMap, ...payload) => this.ctx.emit('bus/broadcast', event, payload);
|
||||
broadcast = (event: keyof EventMap, ...payload) =>
|
||||
this.ctx.emit('bus/broadcast', event, payload, process.env.TRACE_BROADCAST ? new Error().stack : null);
|
||||
|
||||
constructor(ctx) {
|
||||
super(ctx, '$api', true);
|
||||
ctx.mixin('$api', ['addScript', 'setImmediate', 'provideModule', 'injectUI', 'broadcast']);
|
||||
|
||||
@@ -639,6 +639,7 @@ export interface EventDoc {
|
||||
event: number | string;
|
||||
payload: string;
|
||||
expire: Date;
|
||||
trace?: string;
|
||||
}
|
||||
|
||||
export interface OpCountDoc {
|
||||
|
||||
@@ -144,12 +144,13 @@ const id = process.env.exec_mode === 'cluster_mode' ? hostname() : nanoid();
|
||||
|
||||
export async function apply(ctx: Context) {
|
||||
ctx.on('domain/delete', (domainId) => coll.deleteMany({ domainId }));
|
||||
ctx.on('bus/broadcast', (event, payload) => {
|
||||
ctx.on('bus/broadcast', (event, payload, trace) => {
|
||||
collEvent.insertOne({
|
||||
ack: [id],
|
||||
event,
|
||||
payload: BSON.EJSON.stringify(payload),
|
||||
expire: new Date(Date.now() + 10000),
|
||||
trace,
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -38,7 +38,7 @@ export interface EventMap extends KnownHandlerEvents {
|
||||
'database/config': () => VoidReturn
|
||||
|
||||
'system/setting': (args: Record<string, any>) => VoidReturn
|
||||
'bus/broadcast': (event: keyof EventMap | keyof ServerEvents, payload: any) => VoidReturn
|
||||
'bus/broadcast': (event: keyof EventMap | keyof ServerEvents, payload: any, trace?: string) => VoidReturn
|
||||
'monitor/update': (type: 'server' | 'judge', $set: any) => VoidReturn
|
||||
'monitor/collect': (info: any) => VoidReturn
|
||||
'api/update': () => void;
|
||||
|
||||
Reference in new issue
Block a user