chore(M8): unguard debug logs in /api/realtime/solo for Vercel diagnose
Maakt de connect/listen/notify-logs zichtbaar in Vercel function-logs op preview zodat we kunnen zien waarom events niet doorkomen ondanks DIRECT_URL-fix. Logt ook hostname (gemaskeerd) + sprint id bij connect, en pg client errors + end-events voor closed connections. Wordt gestript in ST-806 voordat de PR uit draft gaat. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
fa5af0bb7e
commit
27fb650eba
1 changed files with 20 additions and 20 deletions
|
|
@ -109,9 +109,10 @@ export async function GET(request: NextRequest) {
|
|||
} catch {
|
||||
// already closed
|
||||
}
|
||||
if (process.env.NODE_ENV !== 'production') {
|
||||
console.log(`[realtime/solo] closed: ${reason}`)
|
||||
}
|
||||
// Tijdelijk altijd loggen (geen NODE_ENV-guard) zodat we Vercel
|
||||
// function logs kunnen zien tijdens M8 acceptance. Strippen na
|
||||
// ST-806.
|
||||
console.log(`[realtime/solo] closed: ${reason}`)
|
||||
}
|
||||
|
||||
// Resolve actieve sprint éénmalig per connectie
|
||||
|
|
@ -119,28 +120,24 @@ export async function GET(request: NextRequest) {
|
|||
const activeSprintId = sprint?.id ?? null
|
||||
|
||||
const isPooled = directUrl.includes('pooler.')
|
||||
if (process.env.NODE_ENV !== 'production') {
|
||||
console.log(
|
||||
`[realtime/solo] connecting (${isPooled ? 'POOLED — LISTEN may not work!' : 'direct'})`,
|
||||
)
|
||||
}
|
||||
const hostHint = directUrl.match(/@([^/]+)/)?.[1] ?? 'unknown-host'
|
||||
console.log(
|
||||
`[realtime/solo] connecting (${isPooled ? 'POOLED — LISTEN may not work!' : 'direct'}) host=${hostHint} sprint=${activeSprintId}`,
|
||||
)
|
||||
|
||||
try {
|
||||
await pgClient.connect()
|
||||
await pgClient.query(`LISTEN ${CHANNEL}`)
|
||||
if (process.env.NODE_ENV !== 'production') {
|
||||
console.log(`[realtime/solo] LISTEN ${CHANNEL} ready`)
|
||||
}
|
||||
console.log(`[realtime/solo] LISTEN ${CHANNEL} ready`)
|
||||
} catch (err) {
|
||||
if (process.env.NODE_ENV !== 'production') {
|
||||
console.error('[realtime/solo] pg connect/listen failed:', err)
|
||||
}
|
||||
console.error('[realtime/solo] pg connect/listen failed:', err)
|
||||
enqueue(`event: error\ndata: ${JSON.stringify({ message: 'pg connect failed' })}\n\n`)
|
||||
await cleanup('pg connect failed')
|
||||
return
|
||||
}
|
||||
|
||||
pgClient.on('notification', (msg) => {
|
||||
console.log(`[realtime/solo] RAW notification on channel=${msg.channel} length=${msg.payload?.length ?? 0}`)
|
||||
if (!msg.payload) return
|
||||
let payload: NotifyPayload
|
||||
try {
|
||||
|
|
@ -149,19 +146,22 @@ export async function GET(request: NextRequest) {
|
|||
return
|
||||
}
|
||||
const emit = shouldEmit(payload, productId, activeSprintId, userId)
|
||||
if (process.env.NODE_ENV !== 'production') {
|
||||
console.log(
|
||||
`[realtime/solo] NOTIFY ${payload.entity}:${payload.id} ${payload.op} → ${emit ? 'EMIT' : 'skip'} (sprint=${payload.sprint_id} assignee=${payload.assignee_id} user=${userId})`,
|
||||
)
|
||||
}
|
||||
console.log(
|
||||
`[realtime/solo] NOTIFY ${payload.entity}:${payload.id} ${payload.op} → ${emit ? 'EMIT' : 'skip'} (sprint=${payload.sprint_id} assignee=${payload.assignee_id} user=${userId})`,
|
||||
)
|
||||
if (!emit) return
|
||||
enqueue(`data: ${msg.payload}\n\n`)
|
||||
})
|
||||
|
||||
pgClient.on('error', async () => {
|
||||
pgClient.on('error', async (err) => {
|
||||
console.error('[realtime/solo] pg client error:', err)
|
||||
await cleanup('pg error')
|
||||
})
|
||||
|
||||
pgClient.on('end', () => {
|
||||
console.log('[realtime/solo] pg client end (connection closed)')
|
||||
})
|
||||
|
||||
// Stuur eerst een "ready"-event zodat de client weet dat de connectie staat
|
||||
enqueue(
|
||||
`event: ready\ndata: ${JSON.stringify({
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue