add register
This commit is contained in:
@@ -3,7 +3,7 @@
|
||||
import asyncio
|
||||
import logging
|
||||
from dataclasses import dataclass, field
|
||||
from typing import Dict, Optional, Callable, Coroutine, Any
|
||||
from typing import Dict, Coroutine
|
||||
|
||||
from core.constants import TaskStatus
|
||||
|
||||
@@ -77,21 +77,14 @@ class BackgroundTaskManager:
|
||||
return True
|
||||
|
||||
def _on_task_done(self, task_id: str, task: asyncio.Task) -> None:
|
||||
"""Callback когда задача завершилась."""
|
||||
try:
|
||||
exc = task.exception()
|
||||
if exc:
|
||||
if isinstance(exc, asyncio.CancelledError):
|
||||
logger.info(f"Task {task_id} cancelled (normal)")
|
||||
# Не считаем ошибкой
|
||||
else:
|
||||
logger.error(f"Task {task_id} failed: {exc}")
|
||||
else:
|
||||
logger.info(f"Task {task_id} completed successfully")
|
||||
except asyncio.CancelledError:
|
||||
logger.info(f"Task {task_id} was cancelled")
|
||||
except Exception as e:
|
||||
logger.error(f"Error in task callback: {e}")
|
||||
if task.cancelled():
|
||||
logger.info(f"Task {task_id} cancelled")
|
||||
return
|
||||
exc = task.exception()
|
||||
if exc:
|
||||
logger.error(f"Task {task_id} failed: {exc}")
|
||||
else:
|
||||
logger.info(f"Task {task_id} completed successfully")
|
||||
|
||||
async def cancel_task(self, task_id: str) -> bool:
|
||||
"""
|
||||
@@ -126,7 +119,7 @@ class BackgroundTaskManager:
|
||||
cancelled = 0
|
||||
|
||||
async with self._lock:
|
||||
for task_id, task in list(self._tasks.items()):
|
||||
for task in list(self._tasks.values()):
|
||||
if not task.done():
|
||||
task.cancel()
|
||||
try:
|
||||
|
||||
Reference in New Issue
Block a user