[fix] solution: 온보딩 생성·크롤링 진단·장애 알림 묶음
운영 번들 자동 로그인 자격증명 유출, 온보딩 COPY 잡이 Gemini 429 로 죽던 것, 크롤링 실패가 로그에만 남던 것을 한 번에 정리한다. 실측(2026-09-15 밤, 킹서버): 사진분석 배치가 Gemini 분당 쿼터를 다 써서 같은 키를 쓰는 온보딩 COPY 잡도 같이 429 를 맞고 DEAD 로 갔다 — 확인된 fact 만으로도 편집·발행이 되는데 잡을 죽일 이유가 없었다. - solution/frontend: `VITE_AUTO_LOGIN_ID`·`PW` 를 운영 진입점에 안 넘긴다(자동 로그인은 dev 서버 전용) + `Step5Generating` 겉모습을 이전 카드 스타일로, 데이터는 실제 잡 진행(useGenerationJob) 그대로 - solution/backend: copy_service — Gemini 호출 실패해도 잡을 안 죽이고 fact 만으로 계속. db_session_manager — 유니크 제약 충돌(정상 경로) 로그를 ERROR → WARN. worker/runner + alert_service + teams_webhook — 잡 dead-letter·발행 실패·큐 정체를 Teams 로 알림(영구 저장 + 재시도 + dedupe). `/readyz` 추가. collect_diagnostics(신규) — 크롤링 채널별 실패를 jobs.result 에 구조화해서 싣는다. - postgres-init: 0015(users token_version) · 0016(alert_outbox) 마이그레이션 검증: 백엔드 pytest 759 passed. tsc(solution/frontend) 통과. Teams 알림 실채널 수신 확인.
This commit is contained in:
1 parent
b76144746b
commit
b4085a0e0f
36 files changed
+1320
-84
No files matched your search
@@ -0,0 +1,74 @@
|
||||
"""alert_outbox 원장 접근. services/alert_service.py 가 부른다."""
|
||||
from sqlalchemy import func, select, update
|
||||
|
||||
from common.database.model.models import alert_outbox
|
||||
from common.enums import AlertStatus
|
||||
from common.utils.gtime import GTime
|
||||
|
||||
|
||||
async def latest_unresolved(session, dedupe_key: str):
|
||||
"""이 dedupe_key 로 아직 안 풀린(resolved_at IS NULL) 가장 최근 알림. 없으면 None.
|
||||
|
||||
★ send_alert 의 중복 억제와 resolve_alert 의 "지금 알람 상태인가" 판정이 **같은 질의**를
|
||||
쓴다 — 따로 구현하면 두 판단이 어긋날 수 있다."""
|
||||
result = await session.execute(
|
||||
select(alert_outbox)
|
||||
.where(alert_outbox.dedupe_key == dedupe_key, alert_outbox.deleted.is_(False),
|
||||
alert_outbox.resolved_at.is_(None))
|
||||
.order_by(alert_outbox.created_at.desc())
|
||||
.limit(1)
|
||||
)
|
||||
return result.scalars().first()
|
||||
|
||||
|
||||
async def insert(session, values: dict) -> alert_outbox:
|
||||
row = alert_outbox(**values)
|
||||
session.add(row)
|
||||
await session.flush()
|
||||
return row
|
||||
|
||||
|
||||
async def due_pending(session, limit: int = 20):
|
||||
"""★ `next_attempt_at <= func.now()` — **DB 서버의** 지금 시각과 비교한다. 파이썬에서 계산한
|
||||
GTime.UTC() 와 비교하면 앱 서버와 DB 서버의 시계가 몇 십 ms 만 어긋나도(흔하다 — 별도
|
||||
컨테이너) send_alert 직후 process_outbox 를 부르는 자리에서 방금 넣은 행이 안 잡힐 수
|
||||
있다(실측: 로컬에서 그렇게 재현됐다). 비교를 DB 쪽 시계 하나로 통일하면 이 경합이 없다."""
|
||||
result = await session.execute(
|
||||
select(alert_outbox)
|
||||
.where(alert_outbox.status == AlertStatus.PENDING.value, alert_outbox.deleted.is_(False),
|
||||
alert_outbox.next_attempt_at <= func.now())
|
||||
.order_by(alert_outbox.next_attempt_at)
|
||||
.limit(limit)
|
||||
)
|
||||
return result.scalars().all()
|
||||
|
||||
|
||||
async def mark_sent(session, alert_id) -> None:
|
||||
now = GTime.UTC()
|
||||
await session.execute(
|
||||
update(alert_outbox).where(alert_outbox.alert_id == alert_id)
|
||||
.values(status=AlertStatus.SENT.value, sent_at=now, updated_at=now)
|
||||
)
|
||||
|
||||
|
||||
async def mark_retry(session, alert_id, attempts: int, next_attempt_at) -> None:
|
||||
await session.execute(
|
||||
update(alert_outbox).where(alert_outbox.alert_id == alert_id)
|
||||
.values(attempts=attempts, next_attempt_at=next_attempt_at, updated_at=GTime.UTC())
|
||||
)
|
||||
|
||||
|
||||
async def mark_exhausted(session, alert_id, attempts: int) -> None:
|
||||
"""재시도 상한 소진 — 더 시도하지 않는다(사람이 outbox 를 봐야 한다)."""
|
||||
await session.execute(
|
||||
update(alert_outbox).where(alert_outbox.alert_id == alert_id)
|
||||
.values(status=AlertStatus.FAILED.value, attempts=attempts, updated_at=GTime.UTC())
|
||||
)
|
||||
|
||||
|
||||
async def mark_resolved(session, alert_id) -> None:
|
||||
now = GTime.UTC()
|
||||
await session.execute(
|
||||
update(alert_outbox).where(alert_outbox.alert_id == alert_id)
|
||||
.values(resolved_at=now, updated_at=now)
|
||||
)
|
||||
@@ -173,9 +173,12 @@ class JobQueue:
|
||||
|
||||
return await self._tx(run)
|
||||
|
||||
async def reap(self) -> list[str]:
|
||||
async def reap(self) -> list[dict]:
|
||||
"""만료된 lease(워커 사망 등)의 RUNNING 잡을 회수. 시도 남으면 즉시 재큐, 소진되면 DEAD.
|
||||
회수된 job_id 목록 반환."""
|
||||
|
||||
회수된 잡마다 {job_id, job_type, status, last_error} 를 돌려준다 — worker/runner.py 의
|
||||
run_reaper 가 이 중 DEAD(4) 로 떨어진 것만 골라 알린다(alert_service). job_id 목록만
|
||||
돌려주던 예전 모양보다 한 겹 더 있는 이유가 그것뿐이다."""
|
||||
sql = text("""
|
||||
UPDATE jobs SET
|
||||
status = CASE WHEN attempts >= max_attempts THEN 4 ELSE 1 END,
|
||||
@@ -185,12 +188,15 @@ class JobQueue:
|
||||
worker_id = NULL,
|
||||
updated_at = now()
|
||||
WHERE status = 2 AND lease_until IS NOT NULL AND lease_until < now()
|
||||
RETURNING job_id
|
||||
RETURNING job_id, job_type, status, last_error
|
||||
""")
|
||||
|
||||
async def run(s):
|
||||
rows = (await s.execute(sql)).all()
|
||||
return [str(r[0]) for r in rows]
|
||||
return [
|
||||
{"job_id": str(r[0]), "job_type": r[1], "status": r[2], "last_error": r[3]}
|
||||
for r in rows
|
||||
]
|
||||
|
||||
return await self._tx(run)
|
||||
|
||||
|
||||
Reference in new issue
Block a user