feat(matrix): add configurable graceful sync shutdown

This commit is contained in:
Alexander Minges
2026-02-10 12:20:55 +01:00
parent 988b75624c
commit 7c33d3cbe2
2 changed files with 37 additions and 6 deletions

View File

@@ -49,9 +49,28 @@ class MatrixChannel(BaseChannel):
self._sync_task = asyncio.create_task(self._sync_loop())
async def stop(self) -> None:
"""Stop the Matrix channel with graceful sync shutdown."""
self._running = False
if self.client:
# Request sync_forever loop to exit cleanly.
self.client.stop_sync_forever()
if self._sync_task:
self._sync_task.cancel()
try:
await asyncio.wait_for(
asyncio.shield(self._sync_task),
timeout=self.config.sync_stop_grace_seconds,
)
except asyncio.TimeoutError:
self._sync_task.cancel()
try:
await self._sync_task
except asyncio.CancelledError:
pass
except asyncio.CancelledError:
pass
if self.client:
await self.client.close()