o2o-site-AEO/solution/backend/scheduler/jobs.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

74 lines
3.0 KiB
Python

"""스케줄 잡 로직(what)."""
from common.logger import LOG
"""예약 실행 진입점. 복구 전이는 DB 조건부 UPDATE로 여러 프로세스에서도 안전하다."""
from crud.social_crud import sweep
async def sweep_social_posts():
await sweep()
async def sweep_alert_outbox():
"""대기 중인 알림을 실제로 보낸다(services/alert_service.process_outbox)."""
from services import alert_service
try:
await alert_service.process_outbox()
except Exception as ex: # noqa: BLE001 — 스윕 실패가 스케줄러를 죽이면 안 된다(다음 주기 재시도)
LOG.w(f"[scheduler] 알림 발송 스윕 실패: {type(ex).__name__}: {ex}")
async def sweep_queue_health():
"""잡 큐가 막혔는지 주기적으로 본다 — dead-letter 누적·좀비 실행·오래 밀린 PENDING."""
from crud.job_crud import JobQueue
from services import alert_service
try:
snap = await JobQueue().ops()
except Exception as ex: # noqa: BLE001
LOG.w(f"[scheduler] 큐 상태 조회 실패: {type(ex).__name__}: {ex}")
return
# 기준값: dead-letter 가 최근 1시간에 쌓였거나, 좀비 실행이 있거나, 가장 오래된 PENDING 이 30분 넘게 안 집혔다(정상 워커라면 대기 잡을 몇 초 안에 claim 한다).
problems = []
if snap.get("dead_1h", 0) > 0:
problems.append(f"최근 1시간 dead-letter {snap['dead_1h']}건")
if snap.get("stuck_running", 0) > 0:
problems.append(f"좀비 실행 {snap['stuck_running']}건(lease 만료 또는 10분 초과)")
if snap.get("oldest_pending_sec", 0) > 1800:
problems.append(f"가장 오래된 대기 잡이 {snap['oldest_pending_sec'] // 60}분째 안 집힘")
dedupe_key = "queue_health"
if problems:
await alert_service.send_alert(
kind="queue_stuck",
title="잡 큐 정체",
detail=" · ".join(problems) + f"\n{snap}",
dedupe_key=dedupe_key,
)
else:
await alert_service.resolve_alert(dedupe_key, "잡 큐 정상으로 돌아옴")
async def sweep_blog_drafts():
"""미니 블로그 재고 채우기(services/blog_jobs.generate_drafts)."""
from services import blog_jobs
try:
made = await blog_jobs.generate_drafts()
if made:
LOG.i(f"[scheduler] 미니 블로그 초안 {made}건 생성")
except Exception as ex: # noqa: BLE001 — 생성 실패가 스케줄러를 죽이면 안 된다
LOG.w(f"[scheduler] 미니 블로그 생성 실패: {type(ex).__name__}: {ex}")
async def sweep_blog_mail():
"""검수를 통과한 글을 사장님에게 보낸다(services/blog_jobs.send_reviewed)."""
from services import blog_jobs
try:
sent = await blog_jobs.send_reviewed()
if sent:
LOG.i(f"[scheduler] 미니 블로그 메일 {sent}통 발송")
except Exception as ex: # noqa: BLE001
LOG.w(f"[scheduler] 미니 블로그 발송 실패: {type(ex).__name__}: {ex}")