Skip to content

Latest commit

Β 

History

History
144 lines (100 loc) Β· 5.37 KB

File metadata and controls

144 lines (100 loc) Β· 5.37 KB

CLAUDE.md β€” scripts/

이 ν΄λ”λŠ” devpick-ai μ„œλ²„μ˜ μΌνšŒμ„± μœ ν‹Έλ¦¬ν‹° 슀크립트λ₯Ό λ³΄κ΄€ν•œλ‹€.


폴더 λͺ©μ 

  • μ„œλ²„ μ• ν”Œλ¦¬μΌ€μ΄μ…˜ μ½”λ“œμ— ν¬ν•¨λ˜μ§€ μ•ŠλŠ” 운영/μ΄ˆκΈ°ν™” μž‘μ—…μš© 슀크립트λ₯Ό λ‘”λ‹€
  • λŒ€ν‘œμ μΈ μš©λ„: DB μ΄ˆκΈ°ν™”, 데이터 λ§ˆμ΄κ·Έλ ˆμ΄μ…˜, μ‹œλ“œ 데이터 μ‚½μž…, 인덱슀 생성

슀크립트 μž‘μ„± 원칙

독립 μ‹€ν–‰ κ°€λŠ₯

  • 각 μŠ€ν¬λ¦½νŠΈλŠ” λ‹¨λ…μœΌλ‘œ μ‹€ν–‰ν•  수 μžˆμ–΄μ•Ό ν•œλ‹€
  • μ•± μ„œλ²„(uvicorn)κ°€ μ‹€ν–‰ 쀑이지 μ•Šμ•„λ„ λ™μž‘ν•΄μ•Ό ν•œλ‹€
  • ν•„μš”ν•œ ν™˜κ²½λ³€μˆ˜λŠ” .envμ—μ„œ python-dotenv둜 직접 λ‘œλ“œν•œλ‹€

Idempotent (λ©±λ“±μ„±)

  • 동일 슀크립트λ₯Ό μ—¬λŸ¬ 번 싀행해도 κ²°κ³Όκ°€ 동일해야 ν•œλ‹€
  • 쀑볡 생성, 쀑볡 μ‚½μž…μ΄ λ°œμƒν•˜μ§€ μ•Šλ„λ‘ upsert λ˜λŠ” 쑴재 μ—¬λΆ€ 확인 ν›„ μ²˜λ¦¬ν•œλ‹€
  • PostgreSQL 인덱슀 생성 μ‹œ CREATE INDEX IF NOT EXISTS ꡬ문을 μ‚¬μš©ν•œλ‹€

μ‹€νŒ¨ 처리

  • 슀크립트 μ‹€νŒ¨ μ‹œ λͺ…ν™•ν•œ μ—λŸ¬ λ©”μ‹œμ§€λ₯Ό 좜λ ₯ν•˜κ³  non-zero exit code둜 μ’…λ£Œν•œλ‹€
  • λΆ€λΆ„ μ‹€νŒ¨κ°€ λ°œμƒν•  수 μžˆλŠ” μž‘μ—…μ€ νŠΈλžœμž­μ…˜ λ˜λŠ” λ‘€λ°± λ‘œμ§μ„ κ³ λ €ν•œλ‹€

ν˜„μž¬ 슀크립트

파일 μ„€λͺ…
run_backfill_batch.py 1회 μˆ˜μ§‘ μ‹€ν–‰ β€” PostgreSQL 직접 μ €μž₯ + AI 처리(μš”μ•½Β·ν€΄μ¦ˆΒ·μž„λ² λ”©)
run_scheduler.py 6μ‹œκ°„ 간격 μžλ™ 반볡 μ‹€ν–‰ (APScheduler 기반)
run_collect_and_save.py μˆ˜μ§‘ β†’ 둜컬 JSONL μ €μž₯ μ „μš© (AI 처리 μ—†μŒ, κ°œλ°œΒ·λ””λ²„κ·Έμš©)
run_trend_batch.py νŠΈλ Œλ“œ 뢄석 1회 μ‹€ν–‰ CLI β€” --unit daily/weekly/monthly, --force (DP-386)
run_trend_scheduler.py νŠΈλ Œλ“œ 뢄석 μžλ™ μ‹€ν–‰ μŠ€μΌ€μ€„λŸ¬ β€” daily/weekly/monthly cron (DP-386)
init_postgres.py PostgreSQL UNIQUE 인덱슀 μ΄ˆκΈ°ν™” β€” 배포 μ‹œ 1회 μ‹€ν–‰ (λ©±λ“±μ„± 보μž₯)
init_vectors.py FAISS 벑터 디렉터리 μ΄ˆκΈ°ν™” (Bedrock Titan v2 기반)
reindex_vectors.py FAISS 인덱슀 μž¬λΉŒλ“œ β€” DynamoDB rag_documents 기반 (인덱슀 μœ μ‹€ μ‹œ)
inspect_preprocess.py URL 기반 μ „μ²˜λ¦¬ 좜λ ₯ 확인 (λ””λ²„κ·Έμš©)

run_backfill_batch.py

1회 μˆ˜μ§‘ μ‹€ν–‰. μ†ŒμŠ€λ‹Ή μ΅œλŒ€ 20개 μˆ˜μ§‘ β†’ PostgreSQL 직접 μ €μž₯ β†’ AI 처리(μš”μ•½Β·ν€΄μ¦ˆΒ·μž„λ² λ”©) μžλ™ μ‹€ν–‰.

DATABASE_URL=postgresql://... python scripts/run_backfill_batch.py
  • BackfillCursor(data/raw/backfill_cursor) β€” μ†ŒμŠ€λ³„ μ§„ν–‰ μƒνƒœ(phase/μ»€μ„œ) 파일 관리
  • SentIdStore(data/raw/sent_ids) β€” cross-run dedup
  • μ»€μ„œ phase: backfill(κ³Όκ±° κΈ€ μ „λŸ‰) β†’ incremental(μ΅œμ‹  κΈ€λ§Œ) μžλ™ μ „ν™˜
  • μ†ŒμŠ€λ³„ μ‹€νŒ¨λŠ” κ°œλ³„ catch β€” 전체 λ°°μΉ˜κ°€ μ€‘λ‹¨λ˜μ§€ μ•ŠλŠ”λ‹€

run_scheduler.py

APScheduler 기반 반볡 μ‹€ν–‰κΈ°. μ¦‰μ‹œ 1회 μ‹€ν–‰ ν›„ 6μ‹œκ°„λ§ˆλ‹€ λ°˜λ³΅ν•œλ‹€.

DATABASE_URL=postgresql://... python scripts/run_scheduler.py
# Ctrl+C둜 쀑단
  • BlockingScheduler μ‚¬μš© β€” ν”„λ‘œμ„ΈμŠ€κ°€ μ‚΄μ•„ μžˆλŠ” λ™μ•ˆ 계속 μ‹€ν–‰
  • 도컀/μ„œλ²„ ν™˜κ²½μ—μ„œ μž₯κΈ° μ‹€ν–‰ ν”„λ‘œμ„ΈμŠ€λ‘œ μ‚¬μš©

run_collect_and_save.py

μˆ˜μ§‘ β†’ 둜컬 JSONL μ €μž₯ μ „μš©. AI 처리 μ—†μŒ. κ°œλ°œΒ·λ””λ²„κ·Έ ν™˜κ²½μ—μ„œ μ‚¬μš©.

python scripts/run_collect_and_save.py
  • 좜λ ₯: data/raw/normalized/{source_name}.jsonl (append)

run_trend_batch.py (DP-386)

νŠΈλ Œλ“œ 뢄석 1회 μ‹€ν–‰ CLI.

# period-start λ―Έμž…λ ₯ μ‹œ λ‹¨μœ„λ³„ 직전 κΈ°κ°„ μžλ™ 계산
DATABASE_URL=postgresql://... python scripts/run_trend_batch.py --unit weekly
DATABASE_URL=postgresql://... python scripts/run_trend_batch.py --unit daily --period-start 2026-04-21
DATABASE_URL=postgresql://... python scripts/run_trend_batch.py --unit monthly --force
  • --unit: daily / weekly / monthly
  • --period-start: κΈ°κ°„ μ‹œμž‘ (YYYY-MM-DD). λ―Έμž…λ ₯ μ‹œ μžλ™ 계산
  • --force: κΈ°μ‘΄ μŠ€λƒ…μƒ·μ΄ μžˆμ–΄λ„ μž¬μƒμ„±

run_trend_scheduler.py (DP-386)

νŠΈλ Œλ“œ 뢄석 μžλ™ μ‹€ν–‰ μŠ€μΌ€μ€„λŸ¬. KST κΈ°μ€€ μžμ • 직후에 μ‹€ν–‰ν•œλ‹€.

DATABASE_URL=postgresql://... python scripts/run_trend_scheduler.py
# Ctrl+C둜 쀑단
  • daily: 맀일 00:05 KST
  • weekly: λ§€μ£Ό μ›”μš”μΌ 00:10 KST (직전 ν•œ μ£Ό μ›”~μ›”)
  • monthly: λ§€μ›” 1일 00:15 KST (직전 달)
  • 각 job 독립 try/except β€” κ°œλ³„ μ‹€νŒ¨κ°€ μŠ€μΌ€μ€„λŸ¬ 전체λ₯Ό μ€‘λ‹¨ν•˜μ§€ μ•ŠλŠ”λ‹€

inspect_preprocess.py (DP-216)

μ „μ²˜λ¦¬ 좜λ ₯을 ν™•μΈν•˜λŠ” λ””λ²„κ·Έμš© μŠ€ν¬λ¦½νŠΈλ‹€.

python scripts/inspect_preprocess.py --url https://d2.naver.com/...

μ•žμœΌλ‘œ μΆ”κ°€ κ°€λŠ₯

  • seed_vectors.py β€” 벑터 μž„λ² λ”© 초기 μ‹œλ“œ 데이터 μ‚½μž…
  • backfill_ai_summary.py β€” κΈ°μ‘΄ μ½˜ν…μΈ  μš”μ•½ 일괄 생성
  • eval_runner.py β€” AI 좜λ ₯ ν’ˆμ§ˆ 평가 μ‹€ν–‰

μ‹€ν–‰ 방법 (곡톡)

# κ°€μƒν™˜κ²½ ν™œμ„±ν™” ν›„ μ‹€ν–‰
source .venv/bin/activate          # macOS/Linux
.venv\Scripts\activate             # Windows

# ν™˜κ²½λ³€μˆ˜ λ‘œλ“œλŠ” 슀크립트 λ‚΄λΆ€μ—μ„œ 처리
DATABASE_URL=postgresql://... python scripts/init_postgres.py

μ£Όμ˜μ‚¬ν•­

  • 이 ν΄λ”μ˜ μŠ€ν¬λ¦½νŠΈλŠ” CIμ—μ„œ μžλ™ μ‹€ν–‰λ˜μ§€ μ•ŠλŠ”λ‹€. μˆ˜λ™μœΌλ‘œ μ‹€ν–‰ν•œλ‹€
  • ν”„λ‘œλ•μ…˜ DB에 직접 μ ‘κ·Όν•˜λŠ” μŠ€ν¬λ¦½νŠΈλŠ” μ‹€ν–‰ μ „ λ°˜λ“œμ‹œ νŒ€μ— κ³΅μœ ν•œλ‹€
  • 슀크립트 결과둜 데이터가 변경될 경우 μ‹€ν–‰ μ „ λ°±μ—… μ—¬λΆ€λ₯Ό ν™•μΈν•œλ‹€
  • μŠ€ν¬λ¦½νŠΈμ— μ‹œν¬λ¦Ώ 값을 ν•˜λ“œμ½”λ”©ν•˜μ§€ μ•ŠλŠ”λ‹€. 항상 ν™˜κ²½λ³€μˆ˜λ‘œ μ£Όμž…ν•œλ‹€