mirror of
https://github.com/kjanat/livedash-node.git
synced 2026-01-16 12:32:10 +01:00
feat: implement comprehensive email system with rate limiting and extensive test suite
- Add robust email service with rate limiting and configuration management - Implement shared rate limiter utility for consistent API protection - Create comprehensive test suite for core processing pipeline - Add API tests for dashboard metrics and authentication routes - Fix date range picker infinite loop issue - Improve session lookup in refresh sessions API - Refactor session API routing with better code organization - Update processing pipeline status monitoring - Clean up leftover files and improve code formatting
This commit is contained in:
@ -3,6 +3,7 @@
|
||||
## Issues Identified
|
||||
|
||||
From your logs:
|
||||
|
||||
```
|
||||
Can't reach database server at `ep-tiny-math-a2zsshve-pooler.eu-central-1.aws.neon.tech:5432`
|
||||
[NODE-CRON] [WARN] missed execution! Possible blocking IO or high CPU
|
||||
@ -11,29 +12,33 @@ Can't reach database server at `ep-tiny-math-a2zsshve-pooler.eu-central-1.aws.ne
|
||||
## Root Causes
|
||||
|
||||
1. **Multiple PrismaClient instances** across schedulers
|
||||
2. **No connection retry logic** for temporary failures
|
||||
2. **No connection retry logic** for temporary failures
|
||||
3. **No connection pooling optimization** for Neon
|
||||
4. **Aggressive scheduler intervals** overwhelming database
|
||||
|
||||
## Fixes Applied ✅
|
||||
|
||||
### 1. Connection Retry Logic (`lib/database-retry.ts`)
|
||||
|
||||
- **Automatic retry** for connection errors
|
||||
- **Exponential backoff** (1s → 2s → 4s → 10s max)
|
||||
- **Smart error detection** (only retry connection issues)
|
||||
- **Configurable retry attempts** (default: 3 retries)
|
||||
|
||||
### 2. Enhanced Schedulers
|
||||
|
||||
- **Import Processor**: Added retry wrapper around main processing
|
||||
- **Session Processor**: Added retry wrapper around AI processing
|
||||
- **Graceful degradation** when database is temporarily unavailable
|
||||
|
||||
### 3. Singleton Pattern Enforced
|
||||
|
||||
- **All schedulers now use** `import { prisma } from "./prisma.js"`
|
||||
- **No more separate** `new PrismaClient()` instances
|
||||
- **Shared connection pool** across all operations
|
||||
|
||||
### 4. Neon-Specific Optimizations
|
||||
|
||||
- **Connection limit guidance**: 15 connections (below Neon's 20 limit)
|
||||
- **Extended timeouts**: 30s for cold start handling
|
||||
- **SSL mode requirements**: `sslmode=require` for Neon
|
||||
@ -42,6 +47,7 @@ Can't reach database server at `ep-tiny-math-a2zsshve-pooler.eu-central-1.aws.ne
|
||||
## Immediate Actions Needed
|
||||
|
||||
### 1. Update Environment Variables
|
||||
|
||||
```bash
|
||||
# Add to .env.local
|
||||
USE_ENHANCED_POOLING=true
|
||||
@ -53,6 +59,7 @@ DATABASE_URL="postgresql://user:pass@ep-tiny-math-a2zsshve-pooler.eu-central-1.a
|
||||
```
|
||||
|
||||
### 2. Reduce Scheduler Frequency (Optional)
|
||||
|
||||
```bash
|
||||
# Less aggressive intervals
|
||||
CSV_IMPORT_INTERVAL="*/30 * * * *" # Every 30 min (was 15)
|
||||
@ -61,6 +68,7 @@ SESSION_PROCESSING_INTERVAL="0 */2 * * *" # Every 2 hours (was 1)
|
||||
```
|
||||
|
||||
### 3. Run Configuration Check
|
||||
|
||||
```bash
|
||||
pnpm db:check
|
||||
```
|
||||
@ -71,7 +79,7 @@ pnpm db:check
|
||||
✅ **Resource Efficiency**: Single shared connection pool
|
||||
✅ **Neon Optimization**: Proper connection limits and timeouts
|
||||
✅ **Monitoring**: Health check endpoint for visibility
|
||||
✅ **Graceful Degradation**: Schedulers won't crash on DB issues
|
||||
✅ **Graceful Degradation**: Schedulers won't crash on DB issues
|
||||
|
||||
## Monitoring
|
||||
|
||||
@ -84,8 +92,8 @@ pnpm db:check
|
||||
|
||||
- `lib/database-retry.ts` - New retry utilities
|
||||
- `lib/importProcessor.ts` - Added retry wrapper
|
||||
- `lib/processingScheduler.ts` - Added retry wrapper
|
||||
- `lib/processingScheduler.ts` - Added retry wrapper
|
||||
- `docs/neon-database-optimization.md` - Neon-specific guide
|
||||
- `scripts/check-database-config.ts` - Configuration checker
|
||||
|
||||
The connection issues should be significantly reduced with these fixes! 🎯
|
||||
The connection issues should be significantly reduced with these fixes! 🎯
|
||||
|
||||
Reference in New Issue
Block a user