fix: CancelledError/Exception 경로에도 DB log_completion 추가

task.cancel()로 인한 CancelledError는 streaming loop 바깥에서
잡히므로 별도 log_completion 필요

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Hyungi Ahn
2026-04-06 11:24:29 +09:00
parent 72c488d85d
commit 8c41a5dead

View File

@@ -83,9 +83,17 @@ async def run(job: Job) -> None:
except asyncio.CancelledError:
job_manager.set_status(job.id, JobStatus.cancelled)
await state_stream.push(job.id, "error", {"message": "작업이 취소되었습니다."})
try:
await log_completion(job.id, "cancelled", 0, (time() - start_time) * 1000, time())
except Exception:
pass
except Exception:
logger.exception("Worker failed for job %s", job.id)
job_manager.set_status(job.id, JobStatus.failed)
await state_stream.push(job.id, "error", {"message": "내부 오류가 발생했습니다."})
try:
await log_completion(job.id, "failed", 0, (time() - start_time) * 1000, time())
except Exception:
pass
finally:
await state_stream.push_done(job.id)