fix(task-poller): 捕获 CancelledError 避免关闭时产生 traceback

视频任务轮询在应用关闭时,Redis 异步操作被取消会抛出
CancelledError,由于其继承自 BaseException 而非 Exception,
原有的异常处理无法捕获,导致 APScheduler 打印完整 traceback。
拆分 poll_pending_tasks 为入口方法和 _do_poll 内部方法,
在入口层捕获 CancelledError 后静默返回。
This commit is contained in:
fawney19
2026-02-27 18:23:07 +08:00
parent d2450cbdc1
commit 4855e7cbca

View File

@@ -103,6 +103,13 @@ class TaskPollerService:
scheduler.remove_job(self.adapter.job_id)
async def poll_pending_tasks(self) -> None:
try:
await self._do_poll()
except asyncio.CancelledError:
logger.debug("[{}] poll_pending_tasks cancelled (shutdown?)", self.adapter.task_type)
return
async def _do_poll(self) -> None:
async with self._lock:
token = await self._acquire_redis_lock()
if token is None: