Repository navigation
[Feat] 수집 실행 기록 및 admin 수집 상태·수동 실행 API 추가 - #92
Merged
Merged
Conversation
- scrape_run 테이블 마이그레이션 추가 (타입별 대기/실행 중 run 1개 제한 부분 유니크 인덱스) - cron 실행 시 잡마다 run을 기록하고 성공/실패로 마무리, 같은 타입이 이미 대기/실행 중이면 건너뜀 - 10초 주기로 pending run을 FOR UPDATE SKIP LOCKED로 가져와 실행 (admin API 수동 실행용) - 기동 시 프로세스 종료로 running에 남은 run을 실패 처리 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- GET /api/admin/scrapers: 타입별 최근 run과 최근 성공 run - GET /api/admin/scrape-runs: type/status 필터, 커서 기반 페이지네이션 - GET /api/admin/scrape-runs/:id - POST /api/admin/scrape-runs: pending run 등록 후 202 반환, 이미 대기/실행 중이면 409 - X-ADMIN-API-KEY 헤더를 ADMIN_API_KEY 환경변수와 비교하는 AdminApiKeyGuard 추가 (미설정 시 차단) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- 응답 body에 run id가 있어 헤더가 불필요하고, 전역 prefix(/api)를 하드코딩하던 문제 제거 - @res 및 express Response 의존 제거 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- supabase db push로 마이그레이션을 적용하는 재사용 워크플로우(db-migrate.yml) 추가 - API/Batch CD에서 이미지 빌드와 병렬로 실행하고, 둘 다 성공해야 deploy 진행 - concurrency 그룹으로 두 CD의 동시 호출을 직렬화 (마이그레이션만 바꾼 경우 수동 실행) - SUPABASE_DB_URL 시크릿(Session pooler URI) 필요 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- /api/api-docs 전용 location 블록을 삭제해 /api location에서 함께 처리 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Contributor
|
Navigate logical layers of code changes, visualize relationships, and explore their blast radius. Note Currently processing new changes in this PR. This may take a few minutes, please wait... ⚙️ Run configurationConfiguration used: Repository: GNU-connect/Server-Node/.coderabbit.yaml Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (24)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
4 of 5 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
📌 개요
scrape_run테이블을 작업 큐로 사용합니다. API가 실행 요청을 등록하면 배치가 가져가 실행합니다.✨ 작업 내용
DB (
scrape_run)cron/manual), 상태(pending/running/succeeded/failed), 에러 메시지, 생성·시작·종료 시각을 저장합니다.(type) WHERE status IN ('pending','running')부분 유니크 인덱스를 걸었습니다. 타입별로 대기 또는 실행 중인 run은 하나만 존재할 수 있어서, cron 실행과 수동 실행의 중복 방지를 DB가 맡습니다.배치
pendingrun을FOR UPDATE SKIP LOCKED로 가져와 실행합니다. 등록되지 않은 타입이면 실패 처리합니다.running에 남은 run을 실패 처리합니다. 이렇게 하지 않으면 유니크 인덱스 때문에 해당 타입이 영구히 막힙니다.admin API (
X-ADMIN-API-KEY헤더 필요)/api/admin/scrapers/api/admin/scrape-runstype/status필터, 커서 기반 페이지네이션/api/admin/scrape-runs/:id/api/admin/scrape-runs{ type }로 수동 실행 등록 후 202, 이미 대기/실행 중이면 409AdminApiKeyGuard는 헤더 값을ADMIN_API_KEY환경변수와 비교합니다. 비교는 timing-safe 방식이고, 환경변수가 없으면 모든 요청을 막습니다.X-ADMIN-API-KEY를 입력할 수 있습니다.CI/CD
db-migrate.yml을 추가했습니다.supabase db push로 마이그레이션을 적용하는 재사용 워크플로우입니다.concurrency그룹으로 순서대로 적용됩니다.nginx
/api/api-docs)의 IP 제한을 없앴습니다. 전용 location 블록을 지웠고, 이제/apilocation이 함께 처리합니다.🔥 변경 이유
isRunning)로는 API와 배치 사이에 락을 공유할 수 없습니다. 그래서 중복 실행 방지를 DB 유니크 인덱스로 옮겼습니다. cron 루프 전체의 중복 실행 방지용isRunning은 그대로 둡니다.scrape_run을 조회합니다. 테이블 없이 배포되면 재시작을 반복하므로, 마이그레이션이 deploy보다 먼저 적용되도록 CD에 붙였습니다.🧪 테스트
lint:check,test(5 suites / 26 tests),build통과tsc --noEmit, eslint,test(12 suites / 83 tests) 통과BatchService테스트: cron run 기록, 중복 시 건너뛰기, pending 처리, 실패 후 다음 run 계속, 중단 run 정리 순서ScrapeRunsService테스트: 커서 페이지네이션, 404, 409, 타입별 상태 /AdminApiKeyGuard테스트SKIP LOCKEDclaim, 완료 후 재등록, CHECK 제약,DISTINCT ON조회 확인X-ADMIN-API-KEY보안이 적용되는 것 확인prod.confnginx -t통과SUPABASE_DB_URL을 등록해야 합니다. Session pooler URI(포트 5432)를 쓰고, 비밀번호에 특수문자가 있으면 URL 인코딩해야 합니다.supabase migration list로 운영 DB의 마이그레이션 이력을 확인해야 합니다. 예전 마이그레이션을 직접 적용해서 이력에 빠진 버전이 있으면supabase migration repair --status applied <버전>으로 맞춰야 합니다. 그대로 두면 첫db push가 예전 마이그레이션을 다시 실행하려다 실패합니다..env에ADMIN_API_KEY를 추가해야 합니다(openssl rand -hex 32). 없으면 admin API가 전부 막힙니다.🤖 Generated with Claude Code
Summary by CodeRabbit