- renderer: Node/Playwright, single browser + pooled contexts with concurrency
cap and FIFO queue, Redis render cache (graceful no-op without Redis)
- extractor: FastAPI + Trafilatura, HTML -> {title, text, metadata}
- orchestrator: /scrape (render -> extract) with per-stage trace, aggregated
/health, structured JSON logging on all services
- docker-compose for orchestrator/renderer/extractor/redis with healthchecks
Verified locally: end-to-end scrape of example.com and Wikipedia; error paths
for unreachable hosts and bad schemes.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
22 lines
618 B
Python
22 lines
618 B
Python
import json
|
|
import logging
|
|
import sys
|
|
|
|
|
|
class JsonFormatter(logging.Formatter):
|
|
def format(self, record: logging.LogRecord) -> str:
|
|
return json.dumps(
|
|
{
|
|
"ts": self.formatTime(record),
|
|
"level": record.levelname.lower(),
|
|
"service": "orchestrator",
|
|
"msg": record.getMessage(),
|
|
}
|
|
)
|
|
|
|
|
|
def setup() -> logging.Logger:
|
|
handler = logging.StreamHandler(sys.stdout)
|
|
handler.setFormatter(JsonFormatter())
|
|
logging.basicConfig(level=logging.INFO, handlers=[handler])
|
|
return logging.getLogger("orchestrator")
|