chore(debug): extend /debug-realtime with stats, emit-button and filters
Bouwt de basale luister-tabel uit met diagnostische tooling om de SSE+LISTEN-pipe stress-vrij te kunnen valideren. Toegevoegd: - POST /api/debug/emit-test-notify — vuurt een handmatige pg_notify op scrum4me_changes met een synthetic payload (debug:true) zonder een echte DB-UPDATE te doen. Isoleert de SSE-route van Prisma/triggers. - DebugRealtimeClient: stats-grid (status, reconnects, total events, since last event met >30s rood-warning, largest gap, first-event- time), emit-button, reset-stats, filters op type en entity (incl. "debug only"). - Type/entity kolom in de tabel met kleuring per type. Geen impact op productie- of solo-flow. Tijdelijke testtooling; verwijderen wanneer we deze pagina niet meer nodig hebben. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
83f63b2ebb
commit
93d5f11999
2 changed files with 384 additions and 46 deletions
59
app/api/debug/emit-test-notify/route.ts
Normal file
59
app/api/debug/emit-test-notify/route.ts
Normal file
|
|
@ -0,0 +1,59 @@
|
|||
// TIJDELIJKE debug-endpoint. Stuurt een handmatige pg_notify op
|
||||
// `scrum4me_changes` zonder een echte UPDATE te doen. Bedoeld om de
|
||||
// SSE-pipe te testen los van Prisma/triggers.
|
||||
//
|
||||
// VERWIJDEREN voor M8 out-of-draft.
|
||||
|
||||
import { Client } from 'pg'
|
||||
|
||||
export const runtime = 'nodejs'
|
||||
export const dynamic = 'force-dynamic'
|
||||
|
||||
const CHANNEL = 'scrum4me_changes'
|
||||
|
||||
export async function POST(request: Request) {
|
||||
const directUrl = process.env.DIRECT_URL ?? process.env.DATABASE_URL
|
||||
if (!directUrl) {
|
||||
return Response.json({ error: 'DIRECT_URL/DATABASE_URL niet gezet' }, { status: 500 })
|
||||
}
|
||||
|
||||
let body: unknown = null
|
||||
try {
|
||||
body = await request.json()
|
||||
} catch {
|
||||
// empty body is OK — we vullen defaults in
|
||||
}
|
||||
|
||||
const overrides = (body && typeof body === 'object' ? body : {}) as Record<string, unknown>
|
||||
const payload = {
|
||||
op: 'U',
|
||||
entity: 'task',
|
||||
id: `debug-${Date.now()}`,
|
||||
story_id: 'debug-story',
|
||||
product_id: 'debug-product',
|
||||
sprint_id: null,
|
||||
assignee_id: null,
|
||||
task_status: 'TO_DO',
|
||||
task_sort_order: 1,
|
||||
task_title: 'manual debug emit',
|
||||
changed_fields: ['status'],
|
||||
debug: true,
|
||||
emitted_at: new Date().toISOString(),
|
||||
...overrides,
|
||||
}
|
||||
|
||||
const client = new Client({ connectionString: directUrl })
|
||||
try {
|
||||
await client.connect()
|
||||
// pg_notify met JSON-string als payload — zelfde formaat als de trigger
|
||||
await client.query('SELECT pg_notify($1, $2)', [CHANNEL, JSON.stringify(payload)])
|
||||
return Response.json({ ok: true, payload })
|
||||
} catch (err) {
|
||||
return Response.json(
|
||||
{ ok: false, error: err instanceof Error ? err.message : String(err) },
|
||||
{ status: 500 },
|
||||
)
|
||||
} finally {
|
||||
try { await client.end() } catch {}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue