core: support trace on broadcast

This commit is contained in:
undefined committed 2024-12-09 22:40:39 +08:00
1 parent 8465cd9f0a
commit 6423ae580a
4 files changed
+7 -3

No files matched your search

+3 -1
View File
@@ -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']);
+1
View File
@@ -639,6 +639,7 @@ export interface EventDoc {
event: number | string;
payload: string;
expire: Date;
trace?: string;
}
export interface OpCountDoc {
+2 -1
View File
@@ -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,
});
});
+1 -1
View File
@@ -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;