Resolves #228, resolves #229, resolves #230, resolves #231#268
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Resolves #228, resolves #229, resolves #230, resolves #231
What was done
#228 — Pagination for stream events list
GET /v1/streams/{id}/eventsnow returns{ data, total, hasMore }instead of a bare arraylimit(default50, max500),offset,cursor=<eventId>, anddirection=asc|desccreatedAt)@@index([createdAt])and@@index([streamId, createdAt])composite index toStreamEventinprisma/schema.prisma#229 — Graceful shutdown with SSE connection draining
SIGTERM/SIGINT: sets a shutdown flag → sendsevent: reconnectto all connected SSE clients →stops accepting new SSE connections (
503) → stops the HTTP server → waits up to 30 s for thein-flight indexer batch → disconnects Redis → disconnects Prisma → exits
0(1on timeout)SorobanEventWorker.waitForDrain()tracks the active batch promise and resolves when idlesseService.isShuttingDown()checked in the SSE subscribe handler#230 — Redis pub/sub for horizontal SSE scaling
backend/src/lib/redis.ts: initializes a publisher + subscriber pair usingioredis, with aretryStrategyand graceful fallback — ifREDIS_URLis unset or Redis is unreachable, the serviceruns in single-instance in-process mode automatically
sseService.broadcastToStream/broadcastToUser: when Redis is available, publishes tosse:stream:{id}/sse:user:{key}; otherwise falls back to local broadcastPSUBSCRIBEs tosse:stream:*andsse:user:*on startup and routes incoming messagesto local SSE clients
REDIS_URLadded to.env.examplewith documentationioredis ^5.3.2added topackage.json#231 — Admin metrics endpoint
backend/src/routes/adminRoutes.tsmounted at/v1/adminGET /v1/admin/metrics— requiresAuthorization: Bearer <ADMIN_SECRET>; returns stream counts bystatus, events indexed in last 24 h, SSE connection count, indexer last ledger + lag seconds, and
server uptime
GET /healthupdated to includedb,indexer.status, andindexer.lastLedgerfields; still returns503when DB is downADMIN_SECRETadded to.env.example