여러 줄 주석이 설명보다 경위(예전·실측·지적)를 적고 있어 읽는 사람이 결론을 찾기 어려웠다. - 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>
35 lines
1.1 KiB
Python
35 lines
1.1 KiB
Python
"""작업 단계 기록."""
|
|
from contextlib import asynccontextmanager
|
|
|
|
from crud.job_crud import JobQueue
|
|
|
|
|
|
class JobProgress:
|
|
def __init__(self, job: dict, steps: tuple[str, ...]):
|
|
self.job = job
|
|
self.queue = JobQueue()
|
|
self.state = {
|
|
"attempt": job["attempts"],
|
|
"steps": [{"id": step, "status": "pending"} for step in steps],
|
|
}
|
|
|
|
async def _set(self, step_id: str, status: str, reason: str | None = None):
|
|
step = next(step for step in self.state["steps"] if step["id"] == step_id)
|
|
step.update(status=status, reason=reason)
|
|
if not await self.queue.set_progress(self.job, self.state):
|
|
raise RuntimeError("작업 소유권이 만료되어 진행 기록을 중단합니다")
|
|
|
|
@asynccontextmanager
|
|
async def step(self, step_id: str):
|
|
await self._set(step_id, "running")
|
|
try:
|
|
yield
|
|
except BaseException:
|
|
await self._set(step_id, "failed")
|
|
raise
|
|
else:
|
|
await self._set(step_id, "done")
|
|
|
|
async def skip(self, step_id: str, reason: str):
|
|
await self._set(step_id, "skipped", reason)
|