mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +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);
|
setImmediate = T(setImmediate, clearImmediate);
|
||||||
provideModule = T(provideModule);
|
provideModule = T(provideModule);
|
||||||
injectUI = T(inject);
|
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) {
|
constructor(ctx) {
|
||||||
super(ctx, '$api', true);
|
super(ctx, '$api', true);
|
||||||
ctx.mixin('$api', ['addScript', 'setImmediate', 'provideModule', 'injectUI', 'broadcast']);
|
ctx.mixin('$api', ['addScript', 'setImmediate', 'provideModule', 'injectUI', 'broadcast']);
|
||||||
|
|||||||
@@ -639,6 +639,7 @@ export interface EventDoc {
|
|||||||
event: number | string;
|
event: number | string;
|
||||||
payload: string;
|
payload: string;
|
||||||
expire: Date;
|
expire: Date;
|
||||||
|
trace?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface OpCountDoc {
|
export interface OpCountDoc {
|
||||||
|
|||||||
@@ -144,12 +144,13 @@ const id = process.env.exec_mode === 'cluster_mode' ? hostname() : nanoid();
|
|||||||
|
|
||||||
export async function apply(ctx: Context) {
|
export async function apply(ctx: Context) {
|
||||||
ctx.on('domain/delete', (domainId) => coll.deleteMany({ domainId }));
|
ctx.on('domain/delete', (domainId) => coll.deleteMany({ domainId }));
|
||||||
ctx.on('bus/broadcast', (event, payload) => {
|
ctx.on('bus/broadcast', (event, payload, trace) => {
|
||||||
collEvent.insertOne({
|
collEvent.insertOne({
|
||||||
ack: [id],
|
ack: [id],
|
||||||
event,
|
event,
|
||||||
payload: BSON.EJSON.stringify(payload),
|
payload: BSON.EJSON.stringify(payload),
|
||||||
expire: new Date(Date.now() + 10000),
|
expire: new Date(Date.now() + 10000),
|
||||||
|
trace,
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ export interface EventMap extends KnownHandlerEvents {
|
|||||||
'database/config': () => VoidReturn
|
'database/config': () => VoidReturn
|
||||||
|
|
||||||
'system/setting': (args: Record<string, any>) => 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/update': (type: 'server' | 'judge', $set: any) => VoidReturn
|
||||||
'monitor/collect': (info: any) => VoidReturn
|
'monitor/collect': (info: any) => VoidReturn
|
||||||
'api/update': () => void;
|
'api/update': () => void;
|
||||||
|
|||||||
Reference in new issue
Block a user