운영 번들 자동 로그인 자격증명 유출, 온보딩 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 알림 실채널 수신 확인.
75 lines
3.0 KiB
Python
75 lines
3.0 KiB
Python
"""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)
|
|
)
|