Session 7b: Fix pipeline - body parser, Redis queueing, poller visibility, auto-start

This commit is contained in:
Kev
2026-06-10 01:22:55 -04:00
parent b0890dadae
commit 5c44922937
11 changed files with 322 additions and 27 deletions
+10 -4
View File
@@ -51,7 +51,11 @@ app.use(missionHeader);
// Stripe webhook needs raw body — must be before express.json()
app.use('/api/stripe/webhook', express.raw({ type: 'application/json' }));
app.use(express.json());
// Body parser limit raised to 10MB to accommodate full-slate poller
// payloads. The default 100KB rejected real WNBA slates with 413.
// Per-route limits below can tighten or loosen this for specific paths.
app.use(express.json({ limit: '10mb' }));
app.use(express.urlencoded({ extended: true, limit: '10mb' }));
// Health check — public minimal status (Coolify, uptime monitors). Detailed
// adapter + Python service status only with X-VYNDR-Internal-Key.
@@ -119,9 +123,11 @@ app.use('/api/waitlist', waitlistRoutes);
app.use('/api/pipeline', pipelineRoutes);
app.use('/api/share-card', shareCardRoutes);
app.use('/api/push', pushRoutes);
// Resolution payloads carry full ESPN box scores (50-100KB). Scope a larger
// limit to /api/grading only so the other routes keep the safer 100KB default.
app.use('/api/grading', express.json({ limit: '2mb' }), gradingRoutes);
// Resolution payloads carry full ESPN box scores plus per-game prop
// arrays. Full-slate WNBA / MLB resolves exceed 2MB in practice — keep
// /api/grading aligned with the global 10MB ceiling. Correction sweep
// stays small (just a window-hours integer + flags).
app.use('/api/grading', express.json({ limit: '10mb' }), gradingRoutes);
app.use('/api/grading', express.json({ limit: '256kb' }), correctionRoutes);
const widgetRoutes = require('./routes/widget');
app.use('/api/widget', widgetRoutes);
+10 -3
View File
@@ -11,10 +11,13 @@ let degraded = false;
function getRedisClient() {
if (!client) {
client = new Redis(process.env.REDIS_URL || 'redis://127.0.0.1:6379', {
// Don't block the app starting up if Redis is down at boot. Failed
// commands fall through to the cache-miss path immediately.
// Eager connect — but allow commands to QUEUE while the TCP/auth
// handshake completes. Without offline queueing, pollers booting
// alongside the API throw "Stream isn't writeable" before Redis
// is ready. With queueing, ioredis flushes the backlog the moment
// the connection enters READY state.
lazyConnect: false,
enableOfflineQueue: false,
enableOfflineQueue: true,
maxRetriesPerRequest: 1,
retryStrategy(times) {
// Exponential backoff up to 30s. ioredis keeps trying forever on its
@@ -30,7 +33,11 @@ function getRedisClient() {
}
});
client.on('ready', () => {
// Surface the ready transition in PM2/container logs so operators
// can confirm the connection actually established. Distinct from
// reconnect-after-outage which the line below logs at info.
if (degraded) console.info('[redis] reconnected, leaving degraded mode');
else console.log('[redis] connected and ready');
degraded = false;
});
}
+6 -1
View File
@@ -15,9 +15,14 @@ function getSupabaseClient() {
function getSupabaseServiceClient() {
if (!serviceClient) {
// SUPABASE_SERVICE_ROLE_KEY is the canonical name across .env.example
// and the Next.js side. The fallback to SUPABASE_SERVICE_KEY supports
// any deployment still set with the legacy variable so the rename
// doesn't take down a running instance — remove the fallback once all
// Coolify envs are updated.
serviceClient = createClient(
process.env.SUPABASE_URL,
process.env.SUPABASE_SERVICE_KEY
process.env.SUPABASE_SERVICE_ROLE_KEY || process.env.SUPABASE_SERVICE_KEY
);
}
return serviceClient;