여러 줄 주석이 설명보다 경위(예전·실측·지적)를 적고 있어 읽는 사람이 결론을 찾기 어려웠다. - ts·tsx·js·mjs·css·py 478개: 여러 줄 주석은 첫 문장 한 줄로, 과거형·날짜 문장은 삭제 - 주석 위치는 TypeScript 파서·파이썬 tokenize/ast 로 찾는다 — 문자열 안의 # · /* 는 건드리지 않는다 - eslint·ts·noqa·type: ignore 같은 지시 주석은 그대로 둔다 파이썬 275개 정리 전후 AST 동일, TS 298개 주석 뺀 토큰 동일(빈 JSX 주석 10곳만 차이). site·frontend·admin tsc, site vitest 105 passed Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
69 lines
2.4 KiB
Python
69 lines
2.4 KiB
Python
"""alert_outbox 원장 접근."""
|
|
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) 가장 최근 알림."""
|
|
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 서버의** 지금 시각과 비교한다."""
|
|
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)
|
|
)
|