feat: add background memory pruning task

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-02-26 12:58:12 -05:00
parent 196f8c8ae5
commit 2054ca7b24

16
bot.py
View File

@@ -209,6 +209,22 @@ class BCSBot(commands.Bot):
", ".join(missing),
)
# Start memory pruning background task
if not hasattr(self, "_memory_prune_task") or self._memory_prune_task.done():
self._memory_prune_task = asyncio.create_task(self._prune_memories_loop())
async def _prune_memories_loop(self):
"""Background task that prunes expired memories every 6 hours."""
await self.wait_until_ready()
while not self.is_closed():
try:
count = await self.db.prune_expired_memories()
if count > 0:
logger.info("Pruned %d expired memories.", count)
except Exception:
logger.exception("Memory pruning error")
await asyncio.sleep(6 * 3600) # Every 6 hours
async def close(self):
await self.db.close()
await self.llm.close()