Files
site11/services/pipeline/README.md
jungwoo choi 070032006e feat: Implement async queue-based news pipeline with microservices
Major architectural transformation from synchronous to asynchronous processing:

## Pipeline Services (8 microservices)
- pipeline-scheduler: APScheduler for 30-minute periodic job triggers
- pipeline-rss-collector: RSS feed collection with deduplication (7-day TTL)
- pipeline-google-search: Content enrichment via Google Search API
- pipeline-ai-summarizer: AI summarization using Claude API (claude-sonnet-4-20250514)
- pipeline-translator: Translation using DeepL Pro API
- pipeline-image-generator: Image generation with Replicate API (Stable Diffusion)
- pipeline-article-assembly: Final article assembly and MongoDB storage
- pipeline-monitor: Real-time monitoring dashboard (port 8100)

## Key Features
- Redis-based job queue with deduplication
- Asynchronous processing with Python asyncio
- Shared models and queue manager for inter-service communication
- Docker containerization for all services
- Container names standardized with site11_ prefix

## Removed Services
- Moved to backup: google-search, rss-feed, news-aggregator, ai-writer

## Configuration
- DeepL Pro API: 3abbc796-2515-44a8-972d-22dcf27ab54a
- Claude Model: claude-sonnet-4-20250514
- Redis Queue TTL: 7 days for deduplication

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-09-13 19:22:14 +09:00

3.4 KiB

News Pipeline System

비동기 큐 기반 뉴스 생성 파이프라인 시스템

아키텍처

Scheduler → RSS Collector → Google Search → AI Summarizer → Article Assembly → MongoDB
    ↓            ↓              ↓               ↓                ↓
  Redis Queue  Redis Queue  Redis Queue    Redis Queue     Redis Queue

서비스 구성

1. Scheduler

  • 30분마다 등록된 키워드 처리
  • 오전 7시, 낮 12시, 저녁 6시 우선 처리
  • MongoDB에서 키워드 로드 후 큐에 작업 생성

2. RSS Collector

  • RSS 피드 수집 (Google News RSS)
  • 7일간 중복 방지 (Redis Set)
  • 키워드 관련성 필터링
  • RSS 아이템별 추가 검색 결과 수집
  • 아이템당 최대 3개 결과
  • 작업당 최대 5개 아이템 처리

4. AI Summarizer

  • Claude Haiku로 빠른 요약 생성
  • 200자 이내 한국어 요약
  • 병렬 처리 지원 (3 workers)

5. Article Assembly

  • Claude Sonnet으로 종합 기사 작성
  • 1500자 이내 전문 기사
  • MongoDB 저장 및 통계 업데이트

6. Monitor

  • 실시간 파이프라인 모니터링
  • 큐 상태, 워커 상태 확인
  • REST API 제공 (포트 8100)

시작하기

1. 환경 변수 설정

# .env 파일 확인
CLAUDE_API_KEY=your_claude_api_key
GOOGLE_API_KEY=your_google_api_key
GOOGLE_SEARCH_ENGINE_ID=your_search_engine_id

2. 서비스 시작

cd pipeline
docker-compose up -d

3. 모니터링

# 로그 확인
docker-compose logs -f

# 특정 서비스 로그
docker-compose logs -f scheduler

# 모니터 API
curl http://localhost:8100/api/stats

API 엔드포인트

Monitor API (포트 8100)

  • GET /api/stats - 전체 통계
  • GET /api/queues/{queue_name} - 큐 상세 정보
  • GET /api/keywords - 키워드 목록
  • POST /api/keywords - 키워드 등록
  • DELETE /api/keywords/{id} - 키워드 삭제
  • GET /api/articles - 기사 목록
  • GET /api/articles/{id} - 기사 상세
  • GET /api/workers - 워커 상태
  • POST /api/trigger/{keyword} - 수동 처리 트리거
  • GET /api/health - 헬스 체크

키워드 등록 예시

# 새 키워드 등록
curl -X POST http://localhost:8100/api/keywords \
  -H "Content-Type: application/json" \
  -d '{"keyword": "인공지능", "schedule": "30min"}'

# 수동 처리 트리거
curl -X POST http://localhost:8100/api/trigger/인공지능

데이터베이스

MongoDB Collections

  • keywords - 등록된 키워드
  • articles - 생성된 기사
  • keyword_stats - 키워드별 통계

Redis Keys

  • queue:* - 작업 큐
  • processing:* - 처리 중 작업
  • failed:* - 실패한 작업
  • dedup:rss:* - RSS 중복 방지
  • workers:*:active - 활성 워커

트러블슈팅

큐 초기화

docker-compose exec redis redis-cli FLUSHDB

워커 재시작

docker-compose restart rss-collector

데이터베이스 접속

# MongoDB
docker-compose exec mongodb mongosh -u admin -p password123

# Redis
docker-compose exec redis redis-cli

스케일링

워커 수 조정:

# docker-compose.yml
ai-summarizer:
  deploy:
    replicas: 5  # 워커 수 증가

모니터링 대시보드

브라우저에서 http://localhost:8100 접속하여 파이프라인 상태 확인

로그 레벨 설정

.env 파일에서 조정:

LOG_LEVEL=DEBUG  # INFO, WARNING, ERROR