From 2f724d0c1f48785fd4638c6307358c54015abf90 Mon Sep 17 00:00:00 2001 From: Bram Date: Sat, 12 Jul 2025 16:26:22 +0200 Subject: [PATCH] cleanup --- Dockers/puppeteer-api/README.md | 31 ++++- Dockers/puppeteer-api/app/config.py | 3 + Dockers/puppeteer-api/app/routes/browser.py | 32 ++++- Dockers/puppeteer-api/app/services/browser.py | 104 +++++++++++++++ .../puppeteer-api/app/utils/browser_utils.py | 49 ++++++- Dockers/puppeteer-api/main.py | 95 +++++++++++++- Dockers/puppeteer-api/test_pagination.py | 59 --------- Dockers/puppeteer-api/test_pagination_fix.py | 101 --------------- .../test_playwright_migration.py | 120 ------------------ 9 files changed, 306 insertions(+), 288 deletions(-) delete mode 100644 Dockers/puppeteer-api/test_pagination.py delete mode 100644 Dockers/puppeteer-api/test_pagination_fix.py delete mode 100644 Dockers/puppeteer-api/test_playwright_migration.py diff --git a/Dockers/puppeteer-api/README.md b/Dockers/puppeteer-api/README.md index f0d0975..c881bf0 100644 --- a/Dockers/puppeteer-api/README.md +++ b/Dockers/puppeteer-api/README.md @@ -52,9 +52,17 @@ This project has been successfully migrated from Puppeteer (pyppeteer) to Playwr - **System status endpoint**: `/status` - Monitor CPU, memory, file descriptors - **Browser pool monitoring**: Track active browsers and their ages - **Emergency cleanup endpoint**: `/emergency-cleanup` - Force cleanup when needed +- **Timeout-based cleanup**: `/force-cleanup-old` - Force close old browser/page instances - **Monitoring script**: `monitor.py` - Real-time system monitoring -#### 4. Error Handling +#### 4. Timeout Management + +- **Configurable timeout**: `BROWSER_INSTANCE_TIMEOUT_MINUTES` (default: 10 minutes) +- **Automatic cleanup**: Old browser and page instances are automatically force closed +- **Page tracking**: All page instances are tracked with creation timestamps +- **Health check integration**: Timeout cleanup runs every 2 minutes as part of health checks + +#### 5. Error Handling - **Timeout handling**: 30s timeout for getting browsers from pool - **Emergency recovery**: Auto-cleanup when timeouts occur @@ -70,6 +78,7 @@ API_KEY=your-api-key-here MAX_BROWSERS=3 # Maximum browser instances (default: 3) BROWSER_TTL=1800 # Browser time-to-live in seconds (default: 1800 = 30min) MAX_CONCURRENT_OPERATIONS=5 # Max concurrent operations (default: 5) +BROWSER_INSTANCE_TIMEOUT_MINUTES=10 # Force close old browser/page instances after N minutes (default: 10) CACHE_EXPIRY_HOURS=36 # Cache expiry in hours (default: 36) CLEANUP_CRON=0 3 * * * # Cache cleanup schedule (default: daily at 3 AM) RATE_LIMIT_MINUTE=60 # Requests per minute (default: 60) @@ -82,12 +91,22 @@ RATE_LIMIT_MINUTE=60 # Requests per minute (default: 60) - `GET /` - Visit URL and get HTML content - `GET /seo` - Extract SEO information - `GET /meta` - Extract meta tags and Open Graph data +- `GET /json` - Fetch JSON content from a website + +The `/json` endpoint intelligently extracts JSON data from websites by: + +- Directly parsing JSON responses (when Content-Type is application/json) +- Extracting JSON from `