feat(lps): 검색 API 라우터 — 요청 적재(enqueue) + 상태/큐 통계 조회
커머스 검색요청 계약을 프레임워크(protocol+service+RemoveNoneResponse)로 재구성.
실제 검색은 워커가 큐에서 꺼내 수행하도록 API 는 적재까지만 담당(비동기 분리).
- POST /v1/lps/search: 상품 리스트 → 상품별 SEARCH 잡 적재, product_code 로 활성 중복 방지, job_type→우선순위 매핑
- GET /v1/lps/jobs/{job_id}: 잡 상태/시도/결과 조회
- GET /v1/lps/queue/stats: 상태별 카운트(모니터링)
- protocol/lps_service 추가, job_crud.get() 단건조회, enums LPS_JOB_NOT_FOUND
- tests: 적재/중복/상태/미존재/통계 5건 (ASGI 클라이언트 + 실 lps_db) → 전체 16/16
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
da9bd7750c
commit
bebb6a71e6
7 files changed
+240
-5
No files matched your search
@@ -163,6 +163,27 @@ class JobQueue:
|
||||
|
||||
return await self._tx(run)
|
||||
|
||||
# ---- 단건 조회 ------------------------------------------------------
|
||||
async def get(self, job_id: str) -> dict | None:
|
||||
"""잡 단건 조회(읽기). 없으면 None. status 는 정수(JobStatus 값)."""
|
||||
sql = text("""
|
||||
SELECT job_id, job_type, status, priority, attempts, max_attempts,
|
||||
result, last_error, run_after, created_at, updated_at
|
||||
FROM job WHERE job_id = :id
|
||||
""")
|
||||
s = await DB_SESSION_MNG.start_session(self.DB, DBWRType.DB_READ.value)
|
||||
try:
|
||||
row = (await s.execute(sql, {"id": job_id})).mappings().first()
|
||||
if not row:
|
||||
return None
|
||||
d = dict(row)
|
||||
d["job_id"] = str(d["job_id"])
|
||||
if isinstance(d.get("result"), str):
|
||||
d["result"] = json.loads(d["result"])
|
||||
return d
|
||||
finally:
|
||||
await DB_SESSION_MNG.end_session(self.DB, DBWRType.DB_READ.value)
|
||||
|
||||
# ---- 관측(관리 API/메트릭용) ---------------------------------------
|
||||
async def counts(self) -> dict[str, int]:
|
||||
"""상태별 잡 개수(관리 API·알림용). 수동 psql 스크립트를 대체한다."""
|
||||
|
||||
Reference in new issue
Block a user