Fixed cache shutdown to properly await task cancellation and added names to background tasks.
CI / Formatting (push) Successful in 5s
CI / Linting (push) Successful in 5s
CI / Tests (push) Successful in 22s
CI / Type Checking (push) Successful in 10s
CI / Spelling (push) Successful in 5s

This commit is contained in:
2026-03-22 20:17:06 -04:00
parent 23cc721612
commit c1f967ece9
3 changed files with 14 additions and 7 deletions
+8 -3
View File
@@ -15,6 +15,7 @@
"""TTL cache for recently ingested messages, enabling uningest on delete."""
import asyncio
import contextlib
import time
from dataclasses import dataclass
@@ -101,12 +102,16 @@ class IngestCache:
"""Start the periodic background cleanup task."""
if self._task is not None:
return
self._task = asyncio.create_task(self._cleanup_loop())
self._task = asyncio.create_task(
self._cleanup_loop(), name="ingest-cache-cleanup"
)
def stop(self) -> None:
"""Stop the periodic background cleanup task."""
async def stop(self) -> None:
"""Stop the periodic background cleanup task and wait for it to finish."""
if self._task is not None:
self._task.cancel()
with contextlib.suppress(asyncio.CancelledError):
await self._task
self._task = None
async def _cleanup_loop(self) -> None: