o2o-site-AEO/solution/backend/worker/notify.py
Mina Choi 11d30bb3d1 [chore] solution,admin,ontology: 코드 주석을 한 줄로 — 히스토리 주석 삭제
여러 줄 주석이 설명보다 경위(예전·실측·지적)를 적고 있어 읽는 사람이 결론을 찾기 어려웠다.

- 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>
2026-09-28 16:05:19 +09:00

46 lines
1.3 KiB
Python

"""LISTEN/NOTIFY 리스너 — 잡 적재 시 워커를 즉시 깨운다(폴링 낭비 제거)."""
import asyncio
import asyncpg
from config.server_configs import main_db_config
from crud.job_crud import JOB_NOTIFY_CHANNEL
def _dsn() -> str:
c = main_db_config
pw = f":{c.write_pw}" if c.write_pw else ""
return f"postgresql://{c.write_id}{pw}@{c.write_host}:{c.write_port}/{c.name}"
class JobListener:
"""잡 적재 NOTIFY 를 받아 워커를 깨우는 전용 asyncpg LISTEN 연결(SQLAlchemy 풀과 분리)."""
def __init__(self, channel: str = JOB_NOTIFY_CHANNEL):
self._channel = channel
self._conn: asyncpg.Connection | None = None
self._event = asyncio.Event()
async def start(self):
self._conn = await asyncpg.connect(_dsn())
await self._conn.add_listener(self._channel, self._on_notify)
def _on_notify(self, *_args):
self._event.set()
async def wait(self, timeout: float) -> bool:
"""알림이 오거나 timeout 까지 대기."""
try:
await asyncio.wait_for(self._event.wait(), timeout)
return True
except asyncio.TimeoutError:
return False
finally:
self._event.clear()
async def close(self):
if self._conn is not None:
await self._conn.close()
self._conn = None