MCPcopy Create free account
hub / github.com/ShipSecAI/studio / subscribeToRun

Method subscribeToRun

backend/src/trace/trace.repository.ts:47–75  ·  view source on GitHub ↗

* Subscribe to real-time trace events for a specific run ID using Postgres LISTEN/NOTIFY

(
    runId: string,
    callback: (payload: string) => void,
  )

Source from the content-addressed store, hash-verified

45 * Subscribe to real-time trace events for a specific run ID using Postgres LISTEN/NOTIFY
46 */
47 async subscribeToRun(
48 runId: string,
49 callback: (payload: string) => void,
50 ): Promise<() => Promise<void>> {
51 const client = await this.pool.connect();
52 const channel = `trace_events_${runId}`;
53
54 try {
55 await client.query(`LISTEN "${channel}"`);
56
57 client.on('notification', (msg) => {
58 if (msg.channel === channel && msg.payload) {
59 callback(msg.payload);
60 }
61 });
62
63 // Return unsubscribe function
64 return async () => {
65 try {
66 await client.query(`UNLISTEN "${channel}"`);
67 } finally {
68 client.release();
69 }
70 };
71 } catch (error) {
72 client.release();
73 throw error;
74 }
75 }
76
77 /**
78 * Notify subscribers of new trace events

Callers 1

streamMethod · 0.80

Calls 2

connectMethod · 0.80
queryMethod · 0.80

Tested by

no test coverage detected